SPGridView Clear The Applied Fillter Programmatically SPGridView.ClearFilter()

Standard

I had a scenario like that:

I have a SPGridView with filter allowed, a DropDownList and a search button, the default behavior for the grid is to display all un-deleted users names and status which is ( Disabled or Enabled ). If I select view all users from the drop down and click search button the status is one of three (Deleted – Disabled Or Enabled) then I can filter the SPGridView to display all the deleted users.

The second step is to go the dropdown again and select un-deleted users only and click search button the result is empty grid view because the filter of SPGridView which is Status = ‘Deleted’ is sill applied.

The normal think is to go to search button handler and try to find a method like SPGridView.ClearFilter()
before you bind the grid again, but unfortunately I didn’t find a method like that.

After search on the internet I got a protected method that can do this but ‘it is protected’ the solution was like that the following steps:

1 – Create new class inherit the SPGridView class
2 – Add new method like the following to your class
public void ClearFilter()
{
this.DoFilterPostBackEventProcessing(SPGridView.PostbackFilterCommandClear);
}
3 – Register the new control to your page for example
<%@ Register Assembly=”$SharePoint.Project.AssemblyFullName$” ┬áNamespace=”Project.NewClassNameSpace” TagPrefix=”CustomControl” %>
4 – Use the new control instead of the SPGridView
<CustomControl:NewClassName ID=”_pamsGridView” runat=”server” ……. %> …… </CustomControl:NewClassName%>
5 – Now you will find the ClearFilter method in the your Grid object
enhancedGridView.ClearFilter();

Advertisements