ASP.net Drop down list filter

Baz

Baz

Soldato
Joined
9 Dec 2002
Posts
4,376
Location
Peterborough
Not sure how to go about this..



I would like to use several drop down lists to populate a gridview, with each drop down list narrowing the search results to the next one, if that makes sense...

Example, the first drop down list displays for instance the Make of car, then the second one shows relevent models to that make, then the third one shows the relevent engine sizes, and the fourth one shows the relevent trim levels, and each time you select an item it shows all the results in the gridview. So if you just select "Ford" it shows all models and engine sizes etc, but if you select Ford and Focus it shows just the models and trim for the Ford Focus..



I am aware this may be able to be done in ajax, but I really haven't got the time to learn about ajax.:(
 
You firstly need a datasource that holds the makes of cars. In the example it's a database.

You then need to apply a filter to the model of cars based on the make of cars.

When the Make is selected the Make ID is sent to the database which returns only the models which have the Make ID and binds it to the Model drop down list. If you use AutoPostback on the Model DropDownList, this should auto refresh the page.

Are you using Visual Studio at all? What version of .Net did you want to use?

For simplicity, forget about Ajax.

Code:
//Populate the DDL list for Make
	   void Make()
		{
				Connection1.Open();
				IDataReader Region = spSelectMake.ExecuteReader();
				ddlMake.DataSource = CarMake;
				ddlMake.DataValueField = "ID";
				ddlMake.DataTextField = "Make";
				ddlMake.DataBind();		
	                        Connection1.Close();
		
		}
//Populate the DDL list for Model
		void Model()
		{
				Connection1.Open();
				IDataReader Sector = spSelectModel.ExecuteReader();
				ddlModel.DataSource = Sector;
				ddlModel.DataValueField = "ID";
				ddlModelDataTextField = "Model";
				ddlModel.DataBind();
				Connection1.Close();
		}

This is the basis of it. VS2005 makes if very user friendly to choose your datasource.

Good luck.
 
Back
Top Bottom