ASP.NET 2.0 Drop Down List controls

Discussion in 'ASP .Net Web Controls' started by Geoff Taylor, Jul 18, 2004.

  1. Geoff Taylor

    Geoff Taylor Guest

    I have three drop down list controls on an asp.net 2.0 page. The first
    drop down list displays a list of continents, the second displays a
    list of countries and the third displays a list of provinces. All
    three drop down lists are fed by data sources that use stored
    procedures. The stored procedure for filling the Countries drop down
    list uses a parameter for filtering the countries that should fill the
    list, and the value for that parameter comes from the value of the
    currently selected item in the Continents drop down list.

    The provinces control is implemented in a similar way. It has a stored
    procedure which takes a parameter to filter which provinces to
    display. The value of the parameter comes from the value of the
    selected country in the Countries drop down list.

    So: The filter for provinces depends on the item selected for a
    country. And the filter for countries depends on the item selected as
    a continent. My problem is that I can change a continent by selecting
    a new one in that drop down list, which in turn updates the list of
    items available in the countries drop down list, BUT the provinces
    drop down list is not updated to reflect the fact that the countries
    list has changed because the continents list changed.

    I was hoping that a series of controls which have a chain of
    dependencies on each other would be smart enough to update properly,
    but that does not appear to be so. Is there anything simple that I am
    missing here. Maybe I need to handle an event of some sort and
    implement a bit of server-side code to properly update the controls,
    but I was hoping not.


    The first time I run the page I get these values as the first entries
    in the drop down lists:
    Continent = Africa, Country = Algeria, Province = Adrar

    If i then change the continent to Europe, I get:
    Continent = Europe, Country = United Kingdom, Province = Adrar - so
    the province totally missed the fact that the country has changed.

    Any ideas anyone?

    Thanks in advance,

    Geoff Taylor

    Code is below:


    <table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tr>
    <td
    class="InnerInterfaceTheme">
    <table width="100%"
    cellspacing="0" cellpadding="0" border="0">
    <tr><td colspan="8"
    height="10"></td></tr>
    <tr>
    <td nowrap
    width="10">&nbsp;</td>
    <td nowrap
    width="1">
    <asp:Image
    ID="Step1" Runat="server" ImageUrl="~/Img/step1.gif" />
    </td>

    <td
    style="position : relative; top : -5px;"
    class="FieldsText">&nbsp;Where:

    <asp:DropDownList ID="DropDownListContinents" Runat="server"
    SourceID="SqlContinents"

    DataTextField="ContinentName" DataValueField="pkContinentID"
    AutoPostBack="True">

    </asp:DropDownList>

    <asp:SqlDataSource ID="SqlContinents" Runat="server"
    SelectCommand="igyw_ContinentsSorted"

    ConnectionString="<%$ ConnectionStrings:DBConnString %>">

    </asp:SqlDataSource>&nbsp;&gt;&nbsp;

    <asp:DropDownList ID="DropDownListCountries" Runat="server"
    DataSourceID="SqlCountries"

    DataTextField="Country" DataValueField="pkCountryID"
    AutoPostBack="True">

    </asp:DropDownList>

    <asp:SqlDataSource ID="SqlCountries" Runat="server"
    SelectCommand="igyw_CountriesSorted"

    ConnectionString="<%$ ConnectionStrings:DBConnString %>">

    <SelectParameters>

    <asp:ControlParameter Name="Continent" Type="Int32"
    ControlID="DropDownListContinents"

    PropertyName="SelectedValue"></asp:ControlParameter>

    </SelectParameters>

    </asp:SqlDataSource>&nbsp;&gt;&nbsp;

    <asp:DropDownList ID="DropDownListProvinces" Runat="server"
    DataSourceID="SqlProvinces"

    DataTextField="Province" DataValueField="pkProvinceID"
    AutoPostBack="True">

    </asp:DropDownList>

    <asp:SqlDataSource ID="SqlProvinces" Runat="server"
    SelectCommand="igyw_ProvincesSorted"

    ConnectionString="<%$ ConnectionStrings:DBConnString %>">

    <SelectParameters>

    <asp:ControlParameter Name="Country" Type="Int32"
    ControlID="DropDownListCountries"

    PropertyName="SelectedValue"></asp:ControlParameter>

    </SelectParameters>

    </asp:SqlDataSource>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    Geoff Taylor, Jul 18, 2004
    #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. SirPoonga
    Replies:
    2
    Views:
    754
    Ben Strackany
    Jan 7, 2005
  2. weiwei
    Replies:
    0
    Views:
    1,009
    weiwei
    Jan 5, 2007
  3. msimmons
    Replies:
    0
    Views:
    470
    msimmons
    Jul 16, 2009
  4. Replies:
    5
    Views:
    267
  5. Replies:
    3
    Views:
    284
Loading...

Share This Page