c# - 多个下拉列表

标签 c# asp.net selectedindexchanged

我有 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/

相关文章:

c# - 从动态创建的复选框中获取错误值

wpf - 当组合框位于 ListView 单元格中时如何通过委托(delegate)命令处理 SelectionChanged 事件

c# - 检查数字中的数字是否按升序排列

c# - System.Windows.Forms.Keys.HasFlag 行为异常

c# - 从 C# 搜索公共(public) Outlook 联系人文件夹

c# - 下拉 OnSelectedIndexChanged 未触发

c# - 如何防止滚动条在 gridview 的 selectedindexchanged 上重置

c# - 内存碎片?

c# - "System.ServiceModel.Primitives"- 找不到程序集或找不到依赖项

c# - ObjectDataSource 对注释掉的 GridView 有何 react ?