• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

ASP.NET question involving a checkboxlist and a gridview

PhaZe

Platinum Member
Ok so basically I have a CheckBoxList with 6 options and I want to use that to filter my results shown in a GridView.

I am using a "for each" to iterate through each item in the Checkboxlist, and I have a temporary string variable.

If an item is selected, then the string is modified accordingly. I used some string functions to modify the string to get it how I want it.

Once the string is set, I change the SqlDataSource and set it equal to the string.
SqlDataSource1.SelectCommand = myString;

The GridView has sorting and paging enabled and when I click the check boxes it shows the correct results. (paging is set to ten items per page)

But when I click to see the next page, or if I try to sort by column, the gridview disappears.

It feels like I have data bind or bound issue. Any ideas guys?

Thanks in advance.
 
It looks like your SqlDataSource1.SelectCommand is nothing at first and you are setting it after the checkbox values are complete. Problem is everytime there is a postback the page is instantiated fresh and SqlDataSource1.SelectCommand will be nothing again unless you again set it to be something. So if you are using a custom SelectCommand set it again in the grid sorting, paging events.
 
This is a common issue. To add to what KB said, you'd call GridView.DataBind() on every postback, too. Depending on the DataSource, this is not always necessary - the ObjectDataSource handles this for you automagically.
 
Back
Top