标签:abi down alter item bind csharp hang arp c11
几行代码搞定,太漂亮了,记录总结下。 前台代码如下
<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(); } }
标签:abi down alter item bind csharp hang arp c11
原文地址:https://www.cnblogs.com/shuilong/p/11597752.html