Repeater事件OnItemCommand取得行内控件的方法

2025-05-29 0 76

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

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

复制代码代码如下:


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

复制代码代码如下:


protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "update":
string arg = e.CommandArgument.ToString();//取得参数
//找到激发事件的行内控件,这个很有用,能将更多需要的参数值传递过来。
TextBox txtNum = e.Item.FindControl("txtNum") as TextBox;

//下面执行业务逻辑
string jsStr = "<script>alert('删除成功!" + txtNum.Text + "')</script>";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", jsStr,false);
break;
}
Bind();
}

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 Repeater事件OnItemCommand取得行内控件的方法 https://www.kuaiidc.com/102946.html

相关文章

发表评论
暂无评论