Multiple dropdownlist

本文关键字:dropdownlist Multiple | 更新日期: 2023-09-27 17:50:27

我有4个下拉列表。当我改变第一个下拉菜单时,onselectindexchanged我需要改变所有剩余的下拉菜单值。我正在努力,但我只能改变onselectindexchanged上的相应或下拉值。请给我提供任何例子或指导我任何好的链接。请帮助. .提前感谢。

Multiple dropdownlist

您需要将所有下拉框的AutoPostBack设置为true,并需要为前三个下拉框添加SelectedIndexChanged事件。在SelectedIndexChanged的第一个下拉菜单中,你需要设置第二的选定值,它会触发第二的SelectedIndexChanged,在那里你将有代码来设置第三的选定索引,类似地,你将在wards上做。

在Html

<asp:DropDownList ID="dropdownlist1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropdownlist1_SelectedIndexChanged">
<asp:ListItem Value="1">1</asp:ListItem> 
<asp:ListItem Value="2">2</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="dropdownlist2" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropdownlist2_SelectedIndexChanged">
<asp:ListItem Value="1">1</asp:ListItem> 
<asp:ListItem Value="2">2</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="dropdownlist3" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropdownlist3_SelectedIndexChanged">
<asp:ListItem Value="1">1</asp:ListItem> 
<asp:ListItem Value="2">2</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="dropdownlist4" runat="server" AutoPostBack="true" >
<asp:ListItem Value="1">1</asp:ListItem> 
<asp:ListItem Value="2">2</asp:ListItem>
</asp:DropDownList>

12

后面的代码

protected void dropdownlist1_SelectedIndexChanged(object sender, EventArgs e)
{
       dropdownlist2.SelectedIndex = someIndexValue;
}
protected void dropdownlist2_SelectedIndexChanged(object sender, EventArgs e)
{
       dropdownlist3.SelectedIndex = someIndexValue;
}
protected void dropdownlist3_SelectedIndexChanged(object sender, EventArgs e)
{
       dropdownlist4.SelectedIndex = someIndexValue;
}