[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

2 sql database driven drop-down lists to link up

Development plaform: C# ASP.net 2.x, SQL 2005, MS Visual Studio Pro using Web Developer, IIS 6

Hi there,

I am trying to get these 2 sql database driven drop-down lists to link up.

i.e. depending on what the first drop-down list option is select will determine what the second drop-down list will display.  Essentially, fire-up another sql search for related records etc.

Below is the shell of the program -- these 2 sql-based drop-down menus are working fine independately -- just need to get them to link up.

Could someone please add to this scripting the additional coding I need to consider in order to get it working?

<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
            DataTextField="LeadSourceProviderName" DataValueField="LeadSourceProvider_ID">
        </asp:DropDownList>
        &nbsp; &nbsp;
        <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource2"
            DataTextField="LeadSourceProviderProductName" DataValueField="LeadSourceProviderProducts_ID">
        </asp:DropDownList><br />
        <br />
        <br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:FORTUNEConnectionString %>"
            SelectCommand="SELECT [LeadSourceProvider_ID], [LeadSourceProviderName] FROM [LeadSourceProviders] ORDER BY [LeadSourceProviderName]">
        </asp:SqlDataSource>
        <br />
        <br />
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:FORTUNEConnectionString %>"
            SelectCommand="SELECT [LeadSourceProviderProducts_ID], [LeadSourceProviderProductName], [LeadSourceProvider_ID] FROM [LeadSourceProviderProducts] ORDER BY [LeadSourceProviderProductName]">
        </asp:SqlDataSource>


Thank you in advance for your time and efforts with this enquiry.
0
amillyard
Asked:
amillyard
  • 3
  • 2
1 Solution
 
Sammy AgeilCommented:
AutoPostaback should be set to true in the first Dropdownlist
0
 
amillyardAuthor Commented:
ok, done that -- but this is not making the 2nd dro-down box react any differently, only that the screen page refreshes.
0
 
Sammy AgeilCommented:
The Second SqlDataSource MUST have a relationship between itself and the First Dropdownlist

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:FORTUNEConnectionString %>"
            SelectCommand="SELECT [LeadSourceProviderProducts_ID], [LeadSourceProviderProductName], [LeadSourceProvider_ID] FROM [LeadSourceProviderProducts] WHERE ([LeadSourceProvider_ID] = @LeadProviderId) ORDER BY [LeadSourceProviderProductName]">
<SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="LeadProviderId" PropertyName="SelectedValue"
                    Type="Int32" />
            </SelectParameters>      
 </asp:SqlDataSource>
 
0
 
amillyardAuthor Commented:
100 % spot on -- apprieate your time and efforts with enquiry.

thank you.
0
 
Sammy AgeilCommented:
You welcome :-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now