华域联盟 .Net Repeater事件OnItemCommand取得行内控件的方法

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

记录一下,主要是这句:
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控件与PagedDataSource结合实现分页功能
  • Repeater控件实现编辑、更新、删除等操作示例代码
  • Repeater怎么实现多行间隔显示分隔符
  • Repeater中嵌套Repeater的示例介绍
  • repeater做删除前弹窗询问实例
  • 给Repeater控件里添加序号的5种才常见方法介绍
  • asp.net Repeater 数据绑定的具体实现(图文详解)
  • Repeater控件绑定的三种方式
  • ASP.NET笔记之 Repeater的使用
  • asp.net Repeater分页实例(PageDataSource的使用)
  • Repeater里switch的使用方法
  • Repeater中添加按钮实现点击按钮获取某一行数据的方法

本文由 华域联盟 原创撰写:华域联盟 » Repeater事件OnItemCommand取得行内控件的方法

转载请保留出处和原文链接:https://www.cnhackhy.com/53444.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部