我有一个转发器,我绑定到已过滤的列名,因为它们被应用(当前使用会话,我可能会更改它以循环遍历列以查找过滤器,因为我真的知道网格是如何工作的)。
我在每个过滤列名称旁边都有一个按钮,用于从 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
除了从 RadGrid 中实际删除过滤器外,一切正常。在我遍历列并找到带有我要删除的过滤器的正确列的地方,我重置了过滤器下拉列表和值,效果很好!我可以右键单击标题项,过滤器显示未过滤。但数据保持过滤!如何告诉 RadGrid 根据所选过滤器重新评估其新过滤器值?
我觉得代码的多汁位在这里:
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()