I've got a SPGridView in a webpart that has sorting, filtering, paging and grouping configured. Most of it works fine so far, but it seems like I can't get around this problem:
If I filter the content and sort it afterwards, the column I filtered with, seems to "forget" that it has been filtered. The content is still the filtered content, but you can't remove the filter any longer through the column as usual. If I sort first and then filter, it works.
I'm saving the filterExpression in the ViewState like so many tutorials explain, and set it back to the filterExpression of the DataTable the grid is bound to. This works for the content, but not for the column as it seems. I even found other posts of people who experienced this problem, but never with a solution for it.
Saving the filterExpression:
private void gridDS_Filtering(object sender, ObjectDataSourceFilteringEventArgs e) { ViewState["FilterExpression"] = ((ObjectDataSourceView)sender).FilterExpression; }
Setting the filterExpression of the DataTable when sorting the grid:
private void grid_Sorting(object sender, GridViewSortEventArgs e) { if (ViewState["FilterExpression"] != null) { gridDS.FilterExpression = (string)ViewState["FilterExpression"]; } }
I also tried to do this in the PreRender Method or Page Load, I tried using a global variable instead of the viewstate, but nothing works. Everytime when I sort after i filtered, the column doesn't show anymore, that it has been filtered.
Is this a bug or did I probalbly do something wrong? Is there any way to tell the column it has been filtered manually?