Tuesday, December 9, 2008

How to Retrieve a GridView Based on a CheckBoxList of Items with Asp.Net

The problem is you have a list that you want to retrieve from that contains multiple values. Say for example, you have a list of 5 cities and you want to retrieve a list of people in some combination of those cities. If you use the class SelectValue method with GridView you run out of steam because it’s only one value. What you’d really like to do is pass the CheckBoxList into the GridView as a selection parameter, but unfortunately, when you do that, you just get the one selected value from the CheckBoxList, not all the values.

I’m sure you can make a custom ControlParameter in ObjectDataSource to solve this, but I really don’t have time for that. I just wanted something quick (which I now have and thought I’d share).

Basically, what I did was create an invisible label on my GridView that will get the string of values I want to retrieve, then, my ObjectDataSource gets one value (the string) and parses it into small values. My plan is to do a quick run through of the code here, but then also post the project so you can see for yourself how it works.

Read MOre..

No comments: