Asp.net 如何在中继器中创建事件下拉列表(选定的已更改事件)
我想处理repeater中reach项目的dropdownlist事件(selectedindexchanged) 我有中继器中的每一行:(文本框,文本框,下拉列表) 基于dropdownlist值,我想隐藏和显示另外两个文本框Asp.net 如何在中继器中创建事件下拉列表(选定的已更改事件),asp.net,vb.net,repeater,Asp.net,Vb.net,Repeater,我想处理repeater中reach项目的dropdownlist事件(selectedindexchanged) 我有中继器中的每一行:(文本框,文本框,下拉列表) 基于dropdownlist值,我想隐藏和显示另外两个文本框 我该怎么做?Jquery是您的答案。更改下拉列表事件是您需要的。但您需要从下拉列表所在的同一行获取文本框。你可以很容易地找到jquery代码,jquery的问题是它需要id。id属性是由.net保留的,它会自动分配,这使得获取元素变得很困难。您也可以将类放在下拉列表中。
我该怎么做?Jquery是您的答案。更改下拉列表事件是您需要的。但您需要从下拉列表所在的同一行获取文本框。你可以很容易地找到jquery代码,jquery的问题是它需要
id
。id
属性是由.net保留的,它会自动分配,这使得获取元素变得很困难。您也可以将类放在下拉列表中。或者可以在jquery中使用$('#')。服务器端方法的问题远不止于此(每次选择都发回)@husnain_sys感谢您的有用注释
<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>
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
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;
}
}