I've got a repeater I've bound to column names that are filtered, as they're applied (using sessions currently, I might change this to loop through the columns looking for filters now that I really know how the grid works).
I've got a button next to each filtered column name that is to remove the filter from the RadGrid.
<asp:Repeater ID="repCorpFilters" runat="server" OnItemCommand="repFilters_ItemCommand">
<HeaderTemplate>
Current Filters:
</HeaderTemplate>
<ItemTemplate>
<asp:ImageButton runat="server" CommandName="removefilter" CommandArgument="corp" ImageUrl="../images/Delete.gif" />
<asp:literal ID="litFilter" runat="server" Text='<%#Container.DataItem() %>' />
</ItemTemplate>
<SeparatorTemplate>
,
</SeparatorTemplate>
</asp:Repeater>
Protected Sub repFilters_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs)
Select Case e.CommandName
Case "removefilter"
BindGrid(DirectCast([Enum].Parse(GetType(products), e.CommandArgument), products), Nothing, _
CType(e.Item.FindControl("litFilter"), Literal).Text)
End Select
End Sub
Private Sub BindGrid(ByVal prod As products, Optional ByVal cusipFilter As String = Nothing, Optional ByVal strRemoveFilter As String = Nothing)
Dim dvCorp As DataView = CachedPartialCorp()
If Not IsNothing(cusipFilter) Then
isCusipFiltered = True
dvCorp.RowFilter = "CUSIP IN " & cusipFilter
End If
If Not IsNothing(strRemoveFilter) Then
Dim filters As List(Of String) = RemoveFilter("partialCorpFilters", strRemoveFilter)
If filters.Count = 0 Then
repCorpFilters.Visible = False
Else
repCorpFilters.DataSource = filters
repCorpFilters.DataBind()
End If
For Each gc As GridColumn In dtgCorp.MasterTableView.Columns
With gc
If .IsBoundToFieldName(strRemoveFilter) Then
.CurrentFilterFunction = GridKnownFunction.NoFilter
.CurrentFilterValue = ""
.AndCurrentFilterFunction = GridKnownFunction.NoFilter
.AndCurrentFilterValue = ""
End If
End With
Next
End If
dtgCorp.DataSource = dvCorp
dtgCorp.DataBind()
End Sub
Everything works fine except the actual removal of the filter from the RadGrid. Where I loop through the columns and find the correct column with the filter I'm trying to remove, I reset the filter drop downs and values, that works great! I can right click the header item, and the filter shows not filtered. But the data stays filtered! How do I tell the RadGrid to re-evaluate its new filtervalue based on the selected filters?
The juicy bit of the code I feel is here:
For Each gc As GridColumn In dtgCorp.MasterTableView.Columns
With gc
If .IsBoundToFieldName(strRemoveFilter) Then
.CurrentFilterFunction = GridKnownFunction.NoFilter
.CurrentFilterValue = ""
.AndCurrentFilterFunction = GridKnownFunction.NoFilter
.AndCurrentFilterValue = ""
End If
End With
Next
End If
dtgCorp.DataSource = dvCorp
dtgCorp.DataBind()