Populating Multiple DropDownLists

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • klaul
    New Member
    • Mar 2008
    • 6

    Populating Multiple DropDownLists

    I've been trying to do this for a day and a half now, and am clearly getting nowhere!
    The database I'm using is used to keep a log of service calls to various companies. When the user inserts data, they choose the company from a static list, but the reference number is user-supplied. The data is brought back using a GridView.

    I am trying to create two linked dropdownlists so that I can search the gridview (so that the items on the second dropdownlist are changed according to the
    selection of the first dropdownlist). My problem is that whilst the first dropdown list are static (ie, using <asp:ListItem>) , my second dropdown list is populated directly from the datasource, like so:
    Code:
    <asp:AccessDataSource ID="AccessDataSource3" runat="server" 
    DataFile="~/App_Data/db.mdb" 
    SelectCommand="SELECT DISTINCT [reference] FROM [tbl1]"></asp:AccessDataSource>

    What I want to do is to pick a company from the first dropdown, and all the reference numbers that apply to the company areshown.
    I know there are a hundred and one tutorials on the net on this, but all the ones I have found only deal with linked DDLs where both dropdownlists rely on static data.

    I really don't know where to start on this! I haven't posted any of my code for this because, well, I haven't actually got any yet! Any help is appreciated - am using .Net 2.0, Visual studio 2005. I write in VB, but it's not like there aren't any code converters out there :)
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi klaul,

    This can be achieved by firing a function from the OnSelectedIndex Changed event of your first drop down list.

    In this function you'll need to query your database using the selected value of the first drop down and then bind the returned records to your second one.

    Does this make sense?

    Dr B

    Comment

    Working...