我有一个转发器,我已经绑定了过滤的列名,因为它们被应用(当前使用会话,我可能会改变它以循环查找过滤器的列,现在我真的知道网格是如何工作的) .
我在每个过滤的列名称旁边都有一个按钮,用于从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实际删除过滤器 . 我循环通过列并找到正在尝试删除的过滤器的正确列,我重置过滤器下拉和值,这很好!我可以右键单击 Headers 项,过滤器显示未过滤 . 但数据仍然被过滤!如何告诉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()
2 回答
这是最终做到的代码:)
您是否尝试过将NeedDataSource绑定用于网格而不是使用DataBind()调用绑定?在这种情况下,只需调用网格的Rebind()方法来清除过滤器值 . 另请参阅this demo上如何清除过滤器 .
迪克