We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,787 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Gridview filtering? :/

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

2
Contributors
2
Replies
20 Hours
Discussion Span
1 Year Ago
Last Updated
3
Views
Question
Answered
tukky
Light Poster
32 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

Hearth
Posting Whiz
300 posts since Apr 2008
Reputation Points: 123
Solved Threads: 44
Skill Endorsements: 4

Cheers mate! got it to work :)

tukky
Light Poster
32 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by Hearth

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0603 seconds using 2.69MB