【问题标题】:Multiple dropdownlist多个下拉列表
【发布时间】:2013-01-02 05:18:30
【问题描述】:

我有 4 个下拉列表。当我更改第一个下拉列表时,onselectindexchanged 我需要更改所有剩余的下拉值。 我正在研究它,但我只能更改 onselectindexchanged 上的相应或下一个下拉值。请为我提供任何示例或指导我找到任何好的链接。 请帮忙..提前谢谢。

【问题讨论】:

  • 剩下的下拉值也需要改变什么?
  • 请也向我们展示您的相关代码。这将有助于指出问题。
  • 需要改成默认值。

标签: c# asp.net selectedindexchanged


【解决方案1】:

您需要将所有下拉菜单的 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;
}

【讨论】:

  • 哦..对不起...我很高兴忘记了..:P
猜你喜欢
  • 2021-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-07
  • 1970-01-01
相关资源
最近更新 更多