New to .NET, can I have one drop down box control the data of another drop down box using a database

Discussion in 'ASP .Net' started by SirPoonga, Jan 7, 2005.

  1. SirPoonga

    SirPoonga Guest

    Lets say I have a couple of tables in a database containg car make,
    type, and model. I want to create a drop down box that is populated by
    the makes. Based on that selection run a query to get the types of
    vehicles that make creates. Then baed off that the models that fit
    that make and type.
    Point me in the direction of how to do this.

    Thanks.
     
    SirPoonga, Jan 7, 2005
    #1
    1. Advertising

  2. RE: New to .NET, can I have one drop down box control the data of anot

    One way to do this is set up a data adapter, data set and connection string
    to your database on a web form, then bind the dropdown list to the dataset in
    the page load. You can use a stored procedure or a select query command to
    get the data from the database. The data adapter wizard is pretty good as it
    will prompt for ifnormation like this. If you do a search on data adapter
    you will most likely find many examples.

    "SirPoonga" wrote:

    > Lets say I have a couple of tables in a database containg car make,
    > type, and model. I want to create a drop down box that is populated by
    > the makes. Based on that selection run a query to get the types of
    > vehicles that make creates. Then baed off that the models that fit
    > that make and type.
    > Point me in the direction of how to do this.
    >
    > Thanks.
    >
    >
     
    =?Utf-8?B?UGF1bA==?=, Jan 7, 2005
    #2
    1. Advertising

  3. Yep, pretty straight forward (hmm, should there be a hyphen in there?).

    Check out the ASP.NET QuickStart to learn how to populate a dropdownlist
    from the database, e.g.
    http://samples.gotdotnet.com/QuickS...rl=/quickstart/aspplus/doc/webformsintro.aspx
    http://samples.gotdotnet.com/QuickS...l=/quickstart/aspplus/doc/webdatabinding.aspx

    Try out some samples and tutorials on your own. Once you're familiar with
    ASP.NET, create a web form with 3 ASP.NET DropDownList web form controls on
    it: make, type, model. In your Page_Load event, have some code like this:

    if (!Page.IsPostBack)
    {
    // this code runs when the page first loads
    // populate the make dropdownlist from the database
    }

    Double click the make dropdownlist in the web designer -- a
    make_SelectedIndexChanged method will be generated and assigned to that
    dropdownlist control. Add some code to the make_OnSelectedIndexChanged event
    to populate the type dropdownlist and clear the model dropdownlist . So when
    a user chooses something from the make listbox, the type dropdownlist will
    get automatically populated.

    Double click the type dropdownlist & add some code to it's
    SelectedIndexChanged event to populate the model dropdownlist . So when a
    user chooses something from the type listbox, the model dropdownlist gets
    populated.

    It's pretty easy once you get started. If you ever worked with VB6 forms
    you'll find it's pretty similar -- click forms, add code for events, etc.

    Good luck!

    --
    Ben Strackany
    www.developmentnow.com


    "SirPoonga" <> wrote in message
    news:...
    > Lets say I have a couple of tables in a database containg car make,
    > type, and model. I want to create a drop down box that is populated by
    > the makes. Based on that selection run a query to get the types of
    > vehicles that make creates. Then baed off that the models that fit
    > that make and type.
    > Point me in the direction of how to do this.
    >
    > Thanks.
    >
     
    Ben Strackany, Jan 7, 2005
    #3
    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. Joey Liang via DotNetMonster.com

    How to bind data from database access to drop down list control?

    Joey Liang via DotNetMonster.com, May 13, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    4,339
    Eirik Eldorsen
    May 13, 2005
  2. weiwei
    Replies:
    0
    Views:
    1,035
    weiwei
    Jan 5, 2007
  3. msimmons
    Replies:
    0
    Views:
    498
    msimmons
    Jul 16, 2009
  4. Eagle
    Replies:
    1
    Views:
    322
    Brock Allen
    Jun 6, 2005
  5. Replies:
    5
    Views:
    284
Loading...

Share This Page