1.11M Members

Gridview filtering? :/

 
0
 

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:

http://i40.tinypic.com/fys9i.jpg
(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?
Thanks

 
0
 

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

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

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.

 
0
 

Cheers mate! got it to work :)

Question Answered as of 2 Years Ago by |-|x
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article