dropdownlist autopostback problem

Discussion in 'ASP .Net' started by andy, Mar 28, 2007.

  1. andy

    andy Guest

    Hi,

    I have a form uses several dropdownlists to narrow a set of criteria.
    ( This is in turn used to control what is shown on a gridview. )
    With each, the user selects an entry and then the next dropdownlist
    uses that control's selected value to drive what it shows.
    They're all set to autopostback.
    Everything works fine except where one of the levels only has one
    entry.
    This seems to mess up the next level down and you see the wrong
    results.
    If you fiddle around and select another branch of the tree has more
    than one entry in a list then go back it finds the data.
    So all the control sources etc are OK.

    Any ideas on a work round?

    Code snippet:

    <fieldset style="width:200px;padding:3px">
    <legend>Business Level</legend>
    <h2>Conpany</h2>
    <asp:DropDownList ID="ddlCompanies" width="99%" runat="server"
    DataSourceID="sdsCompanies" DataTextField="Company"
    DataValueField="Company_Id" AutoPostBack="True"
    ToolTip="Company">
    </asp:DropDownList>
    <h2>Business Stream</h2>
    <asp:DropDownList ID="ddlBusiness_Streams" width="99%"
    runat="server" DataSourceID="sdsBusiness_Streams"
    DataTextField="Business_Stream"
    DataValueField="Business_Stream_Id" AutoPostBack="True"
    ToolTip="Business Stream">
    </asp:DropDownList>
    <h2>Operating Group</h2>
    <asp:DropDownList ID="ddlOperating_Groups" width="99%"
    runat="server" AutoPostBack="True" DataSourceID="sdsOperating_Groups"
    DataTextField="Operating_Group"
    DataValueField="Operating_Group_Id" ToolTip="Operating Group">
    </asp:DropDownList>
    <h2>Business Unit</h2>
    <asp:DropDownList ID="ddlBusiness_Units" width="99%"
    runat="server" AutoPostBack="True" DataSourceID="sdsBusiness_Unit"
    DataTextField="Business_Unit"
    DataValueField="Business_Unit_Id" ToolTip="Business Unit" >
    </asp:DropDownList>
    <h2>Division</h2>
    <asp:DropDownList ID="ddlDivisions" width="99%"
    runat="server" AutoPostBack="True" DataSourceID="sdsDivisions"
    DataTextField="Division" DataValueField="Div_No"
    ToolTip="Division">
    </asp:DropDownList>
    </fieldset>

    <asp:SqlDataSource ID="sdsCompanies" runat="server"
    ConnectionString="<%$ ConnectionStrings:SQLConnectionString %>"
    SelectCommand="SELECT [Company_Id], [Company] FROM
    [Companies] ORDER BY [Company]">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sdsBusiness_Streams" runat="server"
    ConnectionString="<%$ ConnectionStrings:SQLConnectionString %>"
    SelectCommand="SELECT [Business_Stream_Id],
    [Business_Stream] FROM [Business_Streams] WHERE ([Company_Id] =
    @Company_Id) ORDER BY [Business_Stream]">
    <SelectParameters>
    <asp:ControlParameter ControlID="ddlCompanies"
    DefaultValue="0" Name="Company_Id"
    PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sdsOperating_Groups" runat="server"
    ConnectionString="<%$ ConnectionStrings:SQLConnectionString %>"
    SelectCommand="SELECT [Operating_Group_Id],
    [Operating_Group] FROM [Operating_Groups] WHERE ([Business_Stream_Id]
    = @Business_Stream_Id)">
    <SelectParameters>
    <asp:ControlParameter ControlID="ddlBusiness_Streams"
    DefaultValue="0" Name="Business_Stream_Id"
    PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sdsBusiness_Unit" runat="server"
    ConnectionString="<%$ ConnectionStrings:SQLConnectionString %>"
    SelectCommand="SELECT [Business_Unit_Id], [Business_Unit]
    FROM [Business_Units] WHERE ([Operating_Group_Id] =
    @Operating_Group_Id)">
    <SelectParameters>
    <asp:ControlParameter ControlID="ddlOperating_Groups"
    DefaultValue="0" Name="Operating_Group_Id"
    PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sdsDivisions" runat="server"
    ConnectionString="<%$ ConnectionStrings:SQLConnectionString %>"
    SelectCommand="SELECT [Div_No], [Division] FROM
    [Divisions] WHERE ([Business_Unit_Id] = @Business_Unit_Id)">
    <SelectParameters>
    <asp:ControlParameter ControlID="ddlBusiness_Units"
    DefaultValue="0" Name="Business_Unit_Id"
    PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
    </asp:SqlDataSource>
    andy, Mar 28, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Null
    Replies:
    1
    Views:
    570
    S. Justin Gengo
    Aug 5, 2003
  2. George Durzi
    Replies:
    0
    Views:
    716
    George Durzi
    Aug 15, 2003
  3. S. Justin Gengo
    Replies:
    0
    Views:
    3,128
    S. Justin Gengo
    Aug 15, 2003
  4. Jaleel Syed via .NET 247

    DropDownList (with AutoPostBack) in a DataGrid

    Jaleel Syed via .NET 247, Apr 23, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    506
    Jaleel Syed via .NET 247
    Apr 23, 2004
  5. Dennis George

    Problem with AutoPostback and DropDownlist / Multipage

    Dennis George, Jun 1, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    178
    Dennis George
    Jun 1, 2005
Loading...

Share This Page