我有 4 个下拉列表。当我更改第一个下拉列表时,onselectindexchanged 我需要更改所有剩余的下拉列表值。 我正在研究它,但我只能更改 onselectindexchanged 上的相应或下一个下拉值。请为我提供任何示例或指导我找到任何好的链接。 请帮忙..提前致谢。
最佳答案
您需要将所有下拉列表的 AutoPostBack 设置为 true,并且需要为前三个下拉列表添加 SelectedIndexChanged 事件。在第一个下拉列表的 SelectedIndexChanged 上,您需要设置第二个下拉列表的选定值,它将触发第二个下拉列表的 SelectedIndexChanged,在那里您将有代码来设置第三个下拉列表的选定索引,类似地,您将在病房上执行此操作。
在 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>
1 2
在代码后面
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;
}
关于c# - 多个下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14117181/