Hey guys, I'm doing a project for university and i have hit a wall. I have a gridview that is connected to a database as shown below:

(menu is incomplete)

I want a drop down box that is populated with the type of food such as (pizzas, burgers etc etc). When the user selects one of the items within the drop down box, how would i filter the gridview to only show the selected type of food? EG
If i was to select Pizzas i would only want the pizzas to be shown..

How would i go about doing this?

6 Years
Discussion Span
Last Post by tukky

Assuming you are using an SQLDataSource to bind the gridview, you can add a control parameter linked to your dropdown like so

   <asp:ControlParameter Name="TypeFilter" ControlID="DropDownList1" PropertyName="SelectedValue" />

Your select query must then include the parameter in the where clause, something like

WHERE Type = @TypeFilter

You can set the DropDownList to AutoPostBack="true" so that the grid will refresh whenever the selection changes.

That's essentially all you need to do.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.