·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> Repeater事件OnItemCommand取得行内控件

Repeater事件OnItemCommand取得行内控件

作者:佚名      ASP.NET网站开发编辑:admin      更新时间:2022-07-23

Repeater事件OnItemCommand取得行内控件

记录一下,主要是这句:TextBox txtNum = e.Item.FindControl("txtNum") as TextBox;

Repeater真是太强了,太灵活。除了Repeater别的都不用。

<table><asp:RepeaterID="rptList"runat="server"OnItemCommand="rptList_ItemCommand"><ItemTemplate><tr><td><asp:TextBoxID="txtNum"runat="server"Text='<%#Eval("PRoNum")%>'></asp:TextBox></td><td><asp:ButtonID="btnUpdate"runat="server"Text="更新"CommandName="update"CommandArgument='<%#Eval("PID")%>' /></td></tr></ItemTemplate></asp:Repeater></table>

protectedvoidrptList_ItemCommand(objectsource, RepeaterCommandEventArgs e){switch(e.CommandName) {case"update":stringarg=e.CommandArgument.ToString();//取得参数//找到激发事件的行内控件,这个很有用,能将更多需要的参数值传递过来。 TextBox txtNum=e.Item.FindControl("txtNum")asTextBox;//下面执行业务逻辑stringjsStr="<script>alert('删除成功!"+txtNum.Text+"')</script>"; Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"alert", jsStr,false);break; } Bind();}