# Making Gridview respond to 2 DropDownList in ASP.net



## raziiq (Dec 23, 2009)

Hi there.

I have got 2 Drop Down Lists on my Form and 1 GridView. I want GridView to display the data according to selection from the Drop Down Lists.

For Example, One Drop Down List contains Names and other contains Dates. Both the Drop Down Lists can post back. So if i select a name from 1st Drop Down list, the Grid View should show all the results according to that Name. Similarly if i select the Date from the other Drop Down List , the Grid View should show the results according to the dates. But i cant figure out as how to bind Grid View to respond to 2 Drop Down List.

BTW i am binding both the Drop Down Lists and the Grid View to the DataSource Objects, which is getting data from the database.

Any Suggestions??


----------



## Fyzbo (Feb 6, 2002)

Your datasource object will need to bind to something that can take in parameters. You didn't mention if you are using a sqldatasource or objectdatasource.

SqlDataSource - you will either need to write a paramaterized select statement including the date and name in your where statement. You could also build a stored procedure that takes the two variables and outputs the data.

ObjectDataSource - you will need a method that can take the two values and return an object you can bind to (datatable, dataset, list of objects, etc.)

Once that is in place you will need to tie it all together by setting postback=true on both dropdownlists. Also on the datasource set it up for the select parameters to look at the dropdownlists.


----------

