Asp.net 基于其他DropdownList VB填充DropdownList
我在网上找到了几个例子来做这件事,但我真的很难让它在VB中工作。(尝试了转换器,但结果不一) 我需要根据第一个下拉列表中的不同值填充下拉列表的选择选项 有人能在VB中提供一个相关的简单示例吗?如果脚本中的值是“硬编码”的,则不必担心。或从表中提取数据的SQL位Asp.net 基于其他DropdownList VB填充DropdownList,asp.net,vb.net,drop-down-menu,Asp.net,Vb.net,Drop Down Menu,我在网上找到了几个例子来做这件事,但我真的很难让它在VB中工作。(尝试了转换器,但结果不一) 我需要根据第一个下拉列表中的不同值填充下拉列表的选择选项 有人能在VB中提供一个相关的简单示例吗?如果脚本中的值是“硬编码”的,则不必担心。或从表中提取数据的SQL位 提前谢谢 您的最佳选择是捕获第一个下拉列表上的SelectedIndexChanged事件,检查该下拉列表的当前值,然后使用该值清除并填充第二个下拉列表中的项目。执行此操作时,请记住将第一个下拉列表的AutoPostBack属性设置为“t
提前谢谢 您的最佳选择是捕获第一个下拉列表上的
SelectedIndexChanged
事件,检查该下拉列表的当前值,然后使用该值清除并填充第二个下拉列表中的项目。执行此操作时,请记住将第一个下拉列表的AutoPostBack
属性设置为“true”
方法是在第一个下拉列表的SelectedIndexChanged事件中填充第二个下拉列表
:
与html源代码相同:
<asp:DropDownList ID="ddlState" runat="server" AutoPostBack="True">
</asp:DropDownList>
<asp:DropDownList ID="ddlCountry" runat="server"
AutoPostBack="True" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged">
</asp:DropDownList>
您可以在ASPX页面中声明性地完成此操作,如下所示:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConnString %>" SelectCommand="SELECT id, name FROM planets"></asp:SqlDataSource>
<asp:DropDownList ID="ddlPlanets" AutoPostBack="true" DataTextField="name" DataValueField="id" DataSourceID="SqlDataSource1" runat="server" AppendDataBoundItems="true" />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:myConnString %>" SelectCommand="SELECT planetid, name FROM moons" FilterExpression="planetid = '{0}'">
<FilterParameters>
<asp:ControlParameter Name="planetid" ControlID="ddlPlanets" PropertyName="SelectedValue" />
</FilterParameters>
</asp:SqlDataSource>
<asp:DropDownList ID="ddlMoons" DataTextField="name" DataValueField="planetid" DataSourceID="SqlDataSource2" runat="server" />
是否尝试了此转换器?
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConnString %>" SelectCommand="SELECT id, name FROM planets"></asp:SqlDataSource>
<asp:DropDownList ID="ddlPlanets" AutoPostBack="true" DataTextField="name" DataValueField="id" DataSourceID="SqlDataSource1" runat="server" AppendDataBoundItems="true" />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:myConnString %>" SelectCommand="SELECT planetid, name FROM moons" FilterExpression="planetid = '{0}'">
<FilterParameters>
<asp:ControlParameter Name="planetid" ControlID="ddlPlanets" PropertyName="SelectedValue" />
</FilterParameters>
</asp:SqlDataSource>
<asp:DropDownList ID="ddlMoons" DataTextField="name" DataValueField="planetid" DataSourceID="SqlDataSource2" runat="server" />