用户名:
密 码: 记住
您当前的位置:首页 > 网络编程 > Net教程

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

时间:2015-01-29  来源:互联网  作者:佚名

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

来顶一下
返回首页
返回首页
推荐资讯
asp.net中C#获取字符串中汉字的个数的具体实现方法 asp.net中C#获取字符串中汉字的个数符串可以包括数字,字母,汉字或者其他的字符。使用Char类型
subsonic3.0插件更新字符串过长引发的异常修复方法 subsonic3.0插件更新字符串过长引发最近公司客服提交了个BUG,说是更新产品详细信息时,有的可以
相关文章
栏目更新
栏目热门