DropDownListboxes - 为什么要添加这些数据?

时间:2016-05-26 06:20:32

标签: c# html asp.net ssms dropdownbox

我有三个下拉列表框,其中填充了“select distinct”查询,乍一看它工作正常。 Ddl1只有数据库中每个项目中的一个,然后ddl2只有每个项目中的一个与ddl1中选择的项目一致,直到你更改ddl1,然后它将ddl2中的内容从第一个选择添加到第二个选择。

只是为了进一步解释发生的事情:

如果第一个有A,B,C并且您选择A,第二个有显示D,E和F.那么如果您决定返回并将第一个更改为B,则第二个具有G,H ,我,它仍然有D,E,F,它应该只有G,H和I

我做错了什么?

以下是我的数据源:

        <asp:SqlDataSource ID="LEDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:AXMAPConnectionString %>" SelectCommand="SELECT DISTINCT [LegalEntity] FROM [AXMAP].[Customers]"></asp:SqlDataSource>
    <asp:SqlDataSource ID="OSEDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:AXMAPConnectionString %>" SelectCommand="SELECT DISTINCT [OldSourceEnvironment] FROM [AXMAP].[Customers] WHERE LegalEntity = @LegalEntity">
        <SelectParameters>
            <asp:ControlParameter ControlID="ddlLegalEntity" PropertyName="SelectedValue" Type="String" Name="LegalEntity" DefaultValue="-- Please Select --" />
        </SelectParameters>
    </asp:SqlDataSource>
                <asp:SqlDataSource ID="OCCDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:AXMAPConnectionString %>" SelectCommand="SELECT DISTINCT [OldCompanyCode] FROM [AXMAP].[Customers] WHERE LegalEntity = @LegalEntity AND OldSourceEnvironment = @OldSourceEnvironment">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="ddlLegalEntity" PropertyName="SelectedValue" Type="String" Name="LegalEntity" DefaultValue="-- Please Select --" />
                        <asp:ControlParameter ControlID="ddlOldSourceEnvironment" PropertyName="SelectedValue" Type="String" Name="OldSourceEnvironment" DefaultValue="-- Please Select --" />
                    </SelectParameters>
    </asp:SqlDataSource>

以下是我的下拉列表:

                <td class="auto-style6">
                <asp:DropDownList ID="ddlLegalEntity" runat="server" AutoPostBack="True" DataSourceID="LEDataSource" DataTextField="LegalEntity" DataValueField="LegalEntity" Width="135px" AppendDataBoundItems="True">
                <asp:ListItem Selected="True" Value="0" Text="-- Please Select --"></asp:ListItem>
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td class="auto-style6">
                <asp:DropDownList ID="ddlOldSourceEnvironment" runat="server" AutoPostBack="true" DataSourceID="OSEDataSource" DataTextField="OldSourceEnvironment" DataValueField="OldSourceEnvironment" AppendDataBoundItems="true" Width="135px">
                <asp:ListItem Selected="True" Value="0" Text="-- Please Select --"></asp:ListItem>                    
                </asp:DropDownList>
            </td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td class="auto-style6">
                <asp:DropDownList ID="ddlOldCompanyCode" runat="server" AutoPostBack="true" DataSourceID="OCCDataSource" DataTextField="OldCompanyCode" DataValueField="OldCompanyCode" AppendDataBoundItems="true" Width="135px">
                <asp:ListItem Selected="True" Value="0" Text="-- Please Select --"></asp:ListItem>  
                </asp:DropDownList>

1 个答案:

答案 0 :(得分:0)

您已设置

 AppendDataBoundItems="true"