zoukankan      html  css  js  c++  java
  • 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();
    }
    //参考MSDN:
    //http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.repeater.itemcommand.aspx
  • 相关阅读:
    (转)很简短,但读完你会感触良多!
    (转)让 win8 快速通过认证的5个提示
    WPF 资源路径解析
    47、SimpleOrientationSensor
    45、SplashScreen
    让IE6也支持position:fixed
    utf8编码引起js输出中文乱码的解决办法(实用)
    javascript的currying函数
    sicily 1036. Crypto Columns
    sicily 6774. Buying Mortadella
  • 原文地址:https://www.cnblogs.com/greatverve/p/1615257.html
Copyright © 2011-2022 走看看