C# 根据第一个下拉框中的选定选项加载下拉框

C# 根据第一个下拉框中的选定选项加载下拉框,c#,asp.net,C#,Asp.net,我想根据我在下拉框1中所做的选择显示第二个下拉框 我是asp.net新手,在asp.net中使用c,我不知道java脚本和jquery,所以我知道html和CSS。代码如下: <asp:DropDownList ID="typeselect" runat="server" AutoPostBack="true" OnSelectedIndexChanged="typeselect_SelectedIndexChanged"> <asp:ListI

我想根据我在下拉框1中所做的选择显示第二个下拉框 我是asp.net新手,在asp.net中使用c,我不知道java脚本和jquery,所以我知道html和CSS。代码如下:

      <asp:DropDownList ID="typeselect" runat="server" AutoPostBack="true" OnSelectedIndexChanged="typeselect_SelectedIndexChanged">
          <asp:ListItem Selected="True" Text="cash" Value="0"></asp:ListItem>
          <asp:ListItem Text="Traveller's cheque" Value="1"></asp:ListItem>
      </asp:DropDownList>
当我从上面的代码中选择旅行支票时,我想得到另一个与我选择现金时不同的下拉框。从上述列表项中选择现金时,以下下拉框为默认值

当用户选择旅行支票时,如何显示上述代码?? 请帮助我实现这一点。。
提前感谢您。

您至少有两种选择 1处理类型SELECT\U SelectedIndexChanged事件,就像您所做的那样。有关更多示例,请参见本页: 这样做的坏处在于,它会在服务器上发布并刷新您的页面。如果你想避免这种情况,你必须使用选项二。
2使用ajax获取网页的部分数据。我认为这个例子应该很符合你的需要:

下面的链接可能会帮助你级联

在您的类型中选择\u SelectedIndexChanged事件

别忘了为typeselect下拉列表设置AutoPostBack=True处理下拉列表的SelectedIndexChanged事件:

this.typeselect.SelectedIndexChanged += new EventHandler(typeselect_SelectedIndexChanged);
otherDropdown.DataTextField = "Name";
otherDropdown.DataValueField = "ID";
otherDropdown.DataSource = IList<T>;
otherDropdown.DataBind();
之后,您可以转到类型选择\u SelectedIndexChanged并检查所选的值。如果是“旅行支票”,您可以绑定第二个下拉列表:

this.typeselect.SelectedIndexChanged += new EventHandler(typeselect_SelectedIndexChanged);
otherDropdown.DataTextField = "Name";
otherDropdown.DataValueField = "ID";
otherDropdown.DataSource = IList<T>;
otherDropdown.DataBind();

我认为jQuery方法对这一点很有好处,因为用一个下拉列表回发整个内容是不好的。

您想用jQuery还是C实现它?好的。提供以下答案,请检查一个空的捕捉块是不允许的!你在上面的代码中使用的infocontainer是什么..你能告诉我这个类是什么意思,它应该包含什么数据吗?@user3181351它应该包含基于第一个下拉列表的第二个下拉列表的详细信息value@user3181351:如果需要,您还可以使用sql查询来重新筛选数据,而不是重新筛选数据