asp.net下拉列表回发

时间:2014-04-09 19:11:44

标签: asp.net sql vb.net visual-studio-2012

我有一个下拉列表列表,说A,B,C,D。所有A,B,C从同一个表(table1)中提取数据。 D从另一个中拉出(table2,但也会在sql查询中使用table1)。我想要实现的是,一旦从A下拉一个值,则自动选择B,C,D的值。 我当前的asp代码只能在选择Dropdown A的随机值时才能生成,B,C可以自动选择值,但不能选择D.第二次选择A的随机值时,所有B,C,D得到值选择。

我的代码如下: 一个

            <asp:DropDownList ID="DropDownListA" class="ddStyle" runat="server" DataSourceID="SqlDataSource2" DataTextField="country" DataValueField="country" AppendDataBoundItems="true" AutoPostBack="True" EnableViewState="true" ViewStateMode="Enabled">
                       <asp:ListItem Text="--Select One--" Value="" Selected="True" />  </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="select distinct country from table1 order by country"></asp:SqlDataSource>

  <asp:DropDownList ID="DropDownList2" class="ddStyle" runat="server" DataSourceID="SqlDataSource1" DataTextField="GICS" DataValueField="GICS" AutoPostBack="True"></asp:DropDownList>
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="select distinct GICS, country from table1 where country=@country">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="DropDownListA" Name="country" PropertyName="SelectedValue" />
                            </SelectParameters>
                        </asp:SqlDataSource>

C

  <asp:DropDownList ID="DropDownListC" class="ddStyle" runat="server" DataSourceID="SqlDataSource3" DataTextField="company" DataValueField="id" AutoPostBack="True"></asp:DropDownList>
                            <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="select company, GICS, country, id from table1 where gics=@gics and country=@country">
                                <SelectParameters>
                                    <asp:ControlParameter ControlID="DropDownListB" Name="gics" PropertyName="SelectedValue" />
                                     <asp:ControlParameter ControlID="DropDownListA" Name="Country" PropertyName="SelectedValue" />
                                </SelectParameters>
                            </asp:SqlDataSource>

d         

                            <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="select edition, company, id from table2 where table2.company in (select company from table1 where table1.id=@id)">
                                <SelectParameters>
                                    <asp:ControlParameter ControlID="DropDownListC" Name="id" PropertyName="SelectedValue" />
                                </SelectParameters>
                            </asp:SqlDataSource>
                            <asp:SqlDataSource ID="SqlDataSource4" runat="server"></asp:SqlDataSource>

我想知道如果从A下拉一个值后如何实现,那么B,C,D的值是自动选择的(我猜D首先选择的原因是由于它的sql查询) 。 谢谢你的建议!

0 个答案:

没有答案