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

S

SirPoonga

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.
 
G

Guest

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.
 
B

Ben Strackany

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top