Search code examples
asp.netdrop-down-menucontrolparameter

My dropdownlist is not showing my hard coded listitem


I have four dropdownlists, all dependant on the one before it, using ControlParameters and AutoPostBack="true", they all work perfectly - except the last one. For some reason, the forth doesn't show my hard coded "--All--" item, and I need this so users have the option to view all entries, or to limit entries based on the selected values. Any advice is much appreciated!

1 (which always show all distinct values, plus the "--All--" option):

 <!-- Division (gt_division) -->
 <asp:DropDownList runat="server" ID="DDLDivision" DataSourceID="DSDivision" DataValueField="gt_division" DataTextField="gt_division" AppendDataBoundItems="true" AutoPostBack="true">
                 <asp:ListItem Text="--All--" Value="" />
            </asp:DropDownList>
            <asp:SqlDataSource ID="DSDivision" ConnectionString="<%$ ConnectionStrings:CDRConnectionString %>" runat="server" SelectCommand="select distinct gt_division from chg_dtl">
            </asp:SqlDataSource>

2 (works fine, the dropdown shows '--All--', plus the distinct values based on the selection in the first dropdown (controlparameter gt_division):

 <!-- Program (bill_area) -->
 <asp:DropDownList runat="server" ID="DDLProgram" DataSourceID="DSProgram" DataValueField="bill_area" DataTextField="bill_area" AppendDataBoundItems="true" AutoPostBack="true">
                <asp:ListItem Text="--All--" Value="" />
            </asp:DropDownList>
            <asp:SqlDataSource ID="DSProgram" ConnectionString="<%$ ConnectionStrings:CDRConnectionString %>" runat="server" SelectCommand="SELECT distinct bill_area FROM chg_dtl WHERE gt_division = @gt_division">
                <SelectParameters>
                    <asp:ControlParameter Name="gt_division" ControlID="DDLDivision" PropertyName="SelectedValue"/>
                </SelectParameters>
            </asp:SqlDataSource>

3 (also works fine, shows '--All--' plus values based on first two dropdowns):

<!-- Location (pos_name) -->
<asp:DropDownList runat="server" ID="DDLLocation" DataSourceID="DSLocation" DataValueField="pos_name" DataTextField="pos_name" AppendDataBoundItems="true" AutoPostBack="true">
                <asp:ListItem Text="--All--" Value="" />
            </asp:DropDownList>
            <asp:SqlDataSource ID="DSLocation" ConnectionString="<%$ ConnectionStrings:CDRConnectionString %>" runat="server" SelectCommand="SELECT distinct pos_name FROM chg_dtl WHERE gt_division = @gt_division and bill_area = @bill_area"
                >
                <SelectParameters>
                    <asp:ControlParameter Name="gt_division" ControlID="DDLDivision" PropertyName="SelectedValue" />
                    <asp:ControlParameter Name="bill_area" ControlID="DDLProgram" PropertyName="SelectedValue" />
                </SelectParameters>
            </asp:SqlDataSource>

4 (which shows the correct distinct values (based on previous three dropdowns) but does not show the '--All--' option on postback of the previous dropdown. So I select Program, and this dropdown populates with the correct distinct values, but '--All--' is missing. I need this option to give users the option to view all, and not just results from the single dropdown selection. I could probably do something in the code behind, but would prefer to keep all dropdowns the same. ):

 <!-- Physician (BILLING_NAME) -->
 <asp:DropDownList runat="server" ID="DDLPhysician" DataSourceID="DSPhysician" DataValueField="billing_prov_name" DataTextField="billing_name" AppendDataBoundItem="true" AutoPostBack="true">
                <asp:ListItem Text="All" Value="" />
            </asp:DropDownList>
            <asp:SqlDataSource ID="DSPhysician" ConnectionString="<%$ ConnectionStrings:CDRConnectionString %>" runat="server"
                SelectCommand="SELECT distinct billing_name 
                               FROM chg_dtl 
                               WHERE gt_division = @gt_division AND bill_area = @bill_area AND pos_name = @pos_name"
                >
                <SelectParameters>
                    <asp:ControlParameter Name="gt_division" ControlID="DDLDivision" PropertyName="SelectedValue" />
                    <asp:ControlParameter Name="bill_area" ControlID="DDLProgram" PropertyName="SelectedValue" />
                    <asp:ControlParameter Name="pos_name" ControlID="DDLLocation" PropertyName="SelectedValue" />
                </SelectParameters>
            </asp:SqlDataSource>

Solution

  • You have 'AppendDataBoundItem' in the 4th dropdownlist instead of 'AppendDataBoundItems'