Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 927105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:47:52+00:00 2026-05-15T19:47:52+00:00

I have two dropdown lists (one dynamically populated, the other not) that determine the

  • 0

I have two dropdown lists (one dynamically populated, the other not) that determine the values of a third dropdown list. The idea is that the first ddl1 is compulsory and ddl2 is optional. How can I get the null value (is not value is selected) of ddl2 once ddl1 value is selected. Thanks!

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:conn %>" SelectCommand="SELECT Category FROM Categories"></asp:SqlDataSource>

  <asp:DropDownList ID="DropDownList1" AutoPostBack="True" runat="server" DataSourceID="SqlDataSource1" DataTextField="Category" DataValueField="Category" AppendDataBoundItems="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
   <asp:ListItem Text="Select category" Value=""/>
   </asp:DropDownList>

   <asp:DropDownList ID="DropDownList2" runat="server">
   <asp:ListItem Text="All types" Value="" />
         <asp:ListItem Value="Policy">Policy</asp:ListItem>
         <asp:ListItem Value="Form">Form</asp:ListItem>
         <asp:ListItem Value="Other">Other</asp:ListItem>
          </asp:DropDownList>

     <asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlDataSource3" DataTextField="DocName" DataValueField="DocID" AppendDataBoundItems="True">
   <asp:ListItem Text="Select document" Value=""/>
   </asp:DropDownList>

code behind:

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        DropDownList3.Items.Clear()
        DropDownList3.Items.Add(New ListItem("Select document", ""))

      If (DropDownList1.SelectedIndex <> 0 Or DropDownList1.SelectedIndex > 0) Then
        SqlDataSource3.SelectCommand = "SELECT DocID, DocName, Category, DocType FROM Doc_LibraryTable WHERE (Category = @Cat) AND (DocType = @DocType OR @DocType IS NULL)"            
        Dim controlDdl1 As ControlParameter = New ControlParameter
        controlDdl1.ControlID = "DropDownList1"
        controlDdl1.Name = "Cat"
        controlDdl1.Type = TypeCode.String
        controlDdl1.PropertyName = "SelectedValue"
        SqlDataSource3.SelectParameters.Clear()
        SqlDataSource3.SelectParameters.Add(controlDdl1)

        Dim controlDdl2 As ControlParameter = New ControlParameter
        controlDdl2.ControlID = "DropDownList2"
        controlDdl2.Name = "DocType"
        controlDdl2.Type = TypeCode.String
        controlDdl2.PropertyName = "SelectedValue"
        SqlDataSource3.SelectParameters.Clear()
        SqlDataSource3.SelectParameters.Add(controlDdl2)
        SqlDataSource3.SelectParameters("DocType").DefaultValue = ""


    End If
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:47:52+00:00Added an answer on May 15, 2026 at 7:47 pm

    Lots of things to change.

    • Both DropDownList1 & DropDownList2 should be autopostback=true, and the event handler should be used for both. As you have it, the user would have to select DropDownList2 and then DropDownList1 for this to work. We’d like them to be able to select them in either order.

    • Next the line DropDownList1.SelectedIndex <> 0 Or DropDownList1.SelectedIndex > 0 is redundant (Any value that would make the second half true would also make the first half true.) If DropDownList1.SelectedIndex <> 0 Then is sufficent.

    • Do not clear the parameter list twice — you’re erasing your first parameter.

    • Finally, the part you wanted. There is no need to use ControlParameter in code. It was intended to be used in cases where you wanted to set the relationship in markup. If you are using code, you can specify the values directly:

      SqlDataSource3.SelectCommand = "SELECT DocID, DocName, Category, DocType " +_
                                      "FROM Doc_LibraryTable "+_
                                      "WHERE (Category = @Cat) "+_
                                      "AND (DocType = @DocType "+_
                                      "OR @DocType IS NULL)"
      
      SqlDataSource3.SelectParameters.Clear() 
      SqlDataSource3.SelectParameters.Add("Cat", TypeCode.String, _ 
               DropDownList1.SelectedValue) 
      SqlDataSource3.SelectParameters.Add("DocType", TypeCode.String, _ 
               DropDownList2.SelectedValue ?? "") 
      

    (P.S., I’m a C# guy, so with luck, I’ve got the line continuations right…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two dropdown lists, one containing a list of countries and one for
I'm creating a server control that basically binds two dropdown lists, one for country
I have a page with two ContentPlaceHolders. One has a DropDown and another UpdatePanel
I have two applications written in Java that communicate with each other using XML
I have an ASP.net table. In several cells I have two dropdown lists. The
I have two classes, and want to include a static instance of one class
I have two threads, one needs to poll a bunch of separate static resources
I have a simple form that lists user names and for each user, the
I have a Gridview in which i have two templatefields of dropdownlist. I bound
Simple ASP.NET application. I have two drop-down controls. On the first-drop down I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.