首页 > Web开发 > 详细

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

时间:2016-01-31 18:40:03      阅读:198      评论:0      收藏:0      [点我收藏+]

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

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

原文:http://www.jb51.net/article/45724.htm

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!