码迷,mamicode.com
首页 > 其他好文 > 详细

Repeater 中TextBox 触发TextChanged事件

时间:2017-03-09 13:26:25      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:open   参数设置   length   abi   datarow   参数   play   bind   span   

两种方法

1.TextBox 绑定TextChanged 并设置AutoPostBack ="true" ,如果不设置AutoPostBack ="true"则不会触发TextChanged事件,然后在对应的方法里面循环Repeater查找改变项

 

部分代码

<ItemTemplate >
    <tr>
        <td style ="width :9%;"><%#Eval("Date")%> <asp:HiddenField ID ="hfkey" runat ="server" Value =‘<%#Eval("ID")%> ‘ /></td>
        <td style ="width :9%;"><%#Eval("FBASalesDays")%></td>
        <td style ="width :9%;"><asp:TextBox ID ="txtUPSShipQty"  runat="server" Text =‘<%#Eval("UPSShipQty")%>‘ AutoPostBack ="true"   OnTextChanged ="btnCal_Click" ></asp:TextBox> </td>
    </tr>
    </ItemTemplate>

 

后台部分代码

技术分享
protected void btnCal_Click(object sender, EventArgs e)
        {
            
            foreach (RepeaterItem item in rpdList.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    HiddenField hfkey = item.FindControl("hfkey") as HiddenField;
                    
                    TextBox txtUPSShipQty = item.FindControl("txtUPSShipQty") as TextBox;
                   
                    DataRow[] rows = dt.Select("ID =‘" + hfkey.Value + "");

                    if (rows != null && rows.Length > 0)
                    {
                       
                        if (rows[0]["UPSShipQty"].ToString().Trim() != txtUPSShipQty.Text.Trim())
                        {
                            rows[0]["UPSShipQty"] = txtUPSShipQty.Text.Trim();

                            CalFBAShipQty2(dt, 3, "UPSShipQty", hfkey.Value.Trim());
                            break;
                        }
                                        
                    }
                }
            }
            rpdList.DataSource = dt;
            rpdList.DataBind();
        }
View Code

 

 

 

2.让TextBox 触发Repeater 的ItemCommand事件,同样需要绑定TextChanged 并设置AutoPostBack ="true",然后在TextChanged事件中调用ItemCommand

 

HTML

<asp:Repeater ID="Repeater1" runat="server" 
  onitemcommand="Repeater1_ItemCommand">
<ItemTemplate>
<%#Eval("txt") %><table>
    <tr>
        <td>
            <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
        </td>
        <td>
            <asp:Button ID="Button1" runat="server" Text="Button"  />
        </td>
        <td>
            <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true"/>
        </td>
    </tr></table>
</ItemTemplate>
</asp:Repeater>

 

后台代码

技术分享
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("id");
        dt.Columns.Add("txt");
        dt.Rows.Add("1", "1txt");
        dt.Rows.Add("2", "2txt");
        Repeater1.DataSource = dt;
        Repeater1.DataBind();
    }
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
    //注意这里的参数设置
    RepeaterCommandEventArgs e1 = new RepeaterCommandEventArgs(((TextBox)sender).NamingContainer as RepeaterItem,sender,new CommandEventArgs("test",null));
    Repeater1_ItemCommand(Repeater1, e1);
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    string ss = e.CommandName;
    if (ss == "test")
        Response.Write("123");
}
View Code

参考:http://bbs.csdn.net/topics/350011338

 

Repeater 中TextBox 触发TextChanged事件

标签:open   参数设置   length   abi   datarow   参数   play   bind   span   

原文地址:http://www.cnblogs.com/lidaying5/p/6525101.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!