我在aspx Web表单中有2个依赖的下拉列表,第一个下拉列表从数据库中获取打印机品牌名称,第二个下拉列表根据在第一个下拉列表中选择的品牌获取模型。
下面链接的代码正在运行,但它使用了回发,这对我来说是一个问题,因为我正在使用制表符,它会在每次回发后不断回到第一个制表符。
我想知道在我的情况下是否有替代邮寄方式。
谢谢
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:PrintXConnectionString_youssef %>" SelectCommand="SELECT * FROM [Brand]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:PrintXConnectionString_youssef %>" SelectCommand="SELECT Distinct P.p_model FROM [Printer] AS P JOIN [Brand] AS B ON P.b_code=B.b_code WHERE (B.b_name = @b_name )">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="b_name" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<label class="control-label col-sm-8">Printer brand:</label>
<asp:DropDownList ID="DropDownList1" AutoPostBack="true" CssClass="form-control" runat="server" DataSourceID="SqlDataSource2" DataTextField="b_name" DataValueField="b_name">
</asp:DropDownList>
<label class="control-label col-sm-8">Model reference:</label>
<asp:DropDownList ID="DropDownList2" runat="server" CssClass="form-control" DataSourceID="SqlDataSource3" DataTextField="p_model" DataValueField="p_model">
</asp:DropDownList>
解决:我在Visual Studio的工具箱中添加了一个脚本管理器和一个AJAX更新面板控件。这是代码:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div class="form-group">
<label class="control-label col-sm-8">Printer Brand:</label>
<asp:DropDownList ID="DropDownList1" AutoPostBack="true" CssClass="form-control" runat="server" DataSourceID="SqlDataSource2" DataTextField="b_name" DataValueField="b_name">
</asp:DropDownList>
</div>
<asp:UpdatePanel ID="printerpanel" runat="server">
<ContentTemplate>
<div class="form-group">
<label class="control-label col-sm-8">Model reference:</label>
<asp:DropDownList ID="DropDownList2" runat="server" CssClass="form-control" DataSourceID="SqlDataSource3" DataTextField="p_model" DataValueField="p_model">
</asp:DropDownList>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>