我有一个转发器,我已经绑定了过滤的列名,因为它们已被应用(使用当前的会话,我可能会改变这个以循环查找过滤器的列,因为我真的知道网格是怎样的作品)。
我在每个过滤的列名称旁边都有一个按钮,用于从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()
答案 0 :(得分:2)
For Each gc As GridColumn In dtg.MasterTableView.Columns
With gc
If .IsBoundToFieldName(strRemoveFilter) Then
dtg.MasterTableView.GetItems(GridItemType.FilteringItem)(0).FireCommandEvent(RadGrid.HeaderContextMenuFilterCommandName, _
New Triplet(strRemoveFilter, New Pair("NoFilter", ""), New Pair("NoFilter", "")))
End If
End With
Next
这是最终做到的代码:)
答案 1 :(得分:1)
您是否尝试过使用NeedDataSource绑定网格而不是使用DataBind()调用绑定?在这种情况下,只需调用网格的Rebind()方法来清除过滤器值。另请参阅this demo上如何清除过滤器。
迪克