Repeater下拉事件触发修改本行数据
Posted shuilong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Repeater下拉事件触发修改本行数据相关的知识,希望对你有一定的参考价值。
几行代码搞定,太漂亮了,记录总结下。 前台代码如下
<asp:Repeater ID="Repeater2" OnItemDataBound="Repeater2_OnItemDataBound" runat="server"> <ItemTemplate> <tr runat="server" id="row"> <td style="text-align: center"> <asp:DropDownList ID="ddlTFDate" Enabled="true" AutoPostBack="true" OnSelectedIndexChanged="ddlTFDate_TextChanged" runat="server"> <asp:ListItem Value="否">否</asp:ListItem> <asp:ListItem Value="是">是</asp:ListItem> </asp:DropDownList> </td> <td style="text-align: center"> <asp:TextBox ID="txtQJC12" Text=‘<%# Eval("QJC12")%>‘ runat="server" Width="80px"></asp:TextBox> </td> </tr> </ItemTemplate> </asp:Repeater>
后台代码如下:
protected void ddlTFDate_TextChanged(object sender, EventArgs e) { DropDownList ddl1 = ((DropDownList)sender).Parent.FindControl("ddlTFDate") as DropDownList; TextBox txt1 = ((DropDownList)sender).Parent.FindControl("txtQJC12") as TextBox; if (ddl1.SelectedItem.Text.Equals("是")) { txt1.Text = DateTime.Now.ToString("yyyy-MM-dd"); } else { txt1.Text = ""; } }
数据下拉加载绑定
protected void Repeater2_OnItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType.Equals(ListItemType.Item) || e.Item.ItemType.Equals(ListItemType.AlternatingItem)) { DropDownList ddl = (DropDownList)e.Item.FindControl("ddlTFDate"); ListItem li = ddl.Items.FindByText(DataBinder.Eval(e.Item.DataItem, "QJC11").ToString().Trim()); if(li!=null) { ddl.ClearSelection(); li.Selected = true; } //ddl.SelectedItem.Value = DataBinder.Eval(e.Item.DataItem, "QJC11").ToString().Trim(); } }
以上是关于Repeater下拉事件触发修改本行数据的主要内容,如果未能解决你的问题,请参考以下文章