我想处理转发器中到达项目的dropdownlist事件(selectedindexchanged)。
我在转发器中有每一行:(文本框,文本框,下拉列表)
根据下拉列表值,我想隐藏并显示另外两个文本框
我该怎么做?
答案 0 :(得分:0)
<asp:Repeater runat="server" ID="rep" >
<ItemTemplate>
<asp:DropDownList ID="drp" runat ="server" OnSelectedIndexChanged="drp_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text ="aa"></asp:ListItem>
<asp:ListItem Text="bb"></asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="txtA" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:Repeater>
在代码隐藏中:
VB.NET:
Protected Sub drp_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim drp As DropDownList = CType(sender, DropDownList)
Dim itm As RepeaterItem = CType(drp.Parent, RepeaterItem)
Dim txtA As TextBox = CType(itm.FindControl("txtA"), TextBox)
If txtA <> Nothing And drp.SelectedValue ="aa" Then
'txtA.Text = "AAA";
txtA.Visible = False
End If End Sub
OR C#:
protected void drp_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList drp = (DropDownList)sender;
RepeaterItem itm = (RepeaterItem)drp.Parent;
TextBox txtA = (TextBox)itm.FindControl("txtA");
if (txtA != null && drp.SelectedValue =="aa")
{
//txtA.Text = "AAA";
txtA.Visible = false;
}
}