Filtering data in GridView in .net2.0

Go To


I have a page that uses GridView to display some data taken from a stored procedure

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnectionString1 %>"
            SelectCommand="p_get_all_students" SelectCommandType="StoredProcedure">

One of the columns returned is studyYear with the possible values: 1,2,3

I would like to add a set of 3 checkboxes to allow filtering of the displayed results by the studyYear

How could I do this?

Ideally I would like to keep the stored procedure as p_get_all_students and only filter the displayed information - so there would be only one initial call to the database.

EDIT The number of rows returned by the stored procedure is from 20 to 200

2009-06-16 10:18
by padn


I'd personally change the way the app was architected. If you want to keep the code the same though, you could hook into the RowDataBound event.

Update- here's an example which should help you.

2009-06-16 10:30
by RichardOD
+1 Thanks Richard. that solution worked but only partially. All the rows would become visible after sorting and also hiding some of the rows was messing up the numbering - I will probably change the design so the sp takes the paramete - padn 2009-06-16 13:24