当前位置: 移动技术网 > IT编程>开发语言>.net > Repeater事件OnItemCommand取得行内控件的方法

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

甘草有什么作用,cf金牌网吧代理器,超级舞者单机版

记录一下,主要是这句:
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();
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网