Repeater 中TextBox 触发TextChanged事件
生活随笔
收集整理的這篇文章主要介紹了
Repeater 中TextBox 触发TextChanged事件
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
兩種方法
1.TextBox 綁定TextChanged 并設(shè)置AutoPostBack ="true" ,如果不設(shè)置AutoPostBack ="true"則不會(huì)觸發(fā)TextChanged事件,然后在對(duì)應(yīng)的方法里面循環(huán)Repeater查找改變項(xiàng)
?
部分代碼
<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>?
后臺(tái)部分代碼
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 觸發(fā)Repeater 的ItemCommand事件,同樣需要綁定TextChanged 并設(shè)置AutoPostBack ="true",然后在TextChanged事件中調(diào)用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>?
后臺(tái)代碼
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) {//注意這里的參數(shù)設(shè)置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
?
轉(zhuǎn)載于:https://www.cnblogs.com/lidaying5/p/6525101.html
總結(jié)
以上是生活随笔為你收集整理的Repeater 中TextBox 触发TextChanged事件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Oracle使用startup与star
- 下一篇: 分解质因数-洛谷P3200 [HNOI