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

所属分类: 网络编程 / ASP.NET 阅读数: 484
收藏 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();
}

更多精彩内容其他人还在看

用ASP.Net实现文件的在线压缩和解压缩

用ASP.Net实现文件的在线压缩和解压缩
收藏 0 赞 0 分享

ASP.NET中文件上传下载方法集合

ASP.NET中文件上传下载方法集合
收藏 0 赞 0 分享

ASP.NET通过Remoting service上传文件

ASP.NET通过Remoting service上传文件
收藏 0 赞 0 分享

ASP.NET2.0服务器控件之Render方法

ASP.NET2.0服务器控件之Render方法
收藏 0 赞 0 分享

ASP.NET2.0 WebRource,开发微调按钮控件

ASP.NET2.0 WebRource,开发微调按钮控件
收藏 0 赞 0 分享

ASP.NET2.0新特性概述

ASP.NET2.0新特性概述
收藏 0 赞 0 分享

介绍几个ASP.NET中容易忽略但却很重要的方法函数

介绍几个ASP.NET中容易忽略但却很重要的方法函数
收藏 0 赞 0 分享

asp.net2.0如何加密数据库联接字符串

asp.net2.0如何加密数据库联接字符串
收藏 0 赞 0 分享

用.NET 2.0压缩/解压功能处理大型数据

用.NET 2.0压缩/解压功能处理大型数据
收藏 0 赞 0 分享

ASP.NET入门随想之检票的老太太

ASP.NET入门随想之检票的老太太
收藏 0 赞 0 分享
查看更多