我目前正在编写一个.Net web应用程序,使用SortedBindingList和FilteredBindingList。我遇到的一个问题是,FilteredBindingList匹配部分匹配和完全匹配。当基于用户输入(名称、标题等)进行过滤时,这是很好的,但是当过滤与之相关的ID时,它匹配完整的ID和包含部分匹配的任何ID。下面我举了一个例子。
<select id="CustomerName">
<option value="1">Frank</option>
<option value="2">Bert</option>
<option value="11">Jane</option>
</select>如果我要对select列表的'value‘属性进行筛选,在这个实例中它是customers唯一标识符。使用FilteredBindingList,选择伯特或简将只返回与伯特或简相关的行。选择Frank将返回与Frank和Jane关联的行,因为在Frank和Jane的记录中都可以匹配1的值。
我的vb.Net代码如下:
Dim filteredList As New FilteredBingList(Of CustomerOrders)(sortedList)
filteredList.ApplyFilter("CustomerID", CustomerName.SelectedValue)
e.BusinessObject = filteredList我是不是错过了一步?因为似乎没有明显的方法来阻止过滤器匹配部分命中。
非常感谢你抽出时间来阅读/回复我的问题。
干杯,
安迪
发布于 2015-09-10 14:31:47
经过大量的研究和谷歌搜索(我的google-fu很弱),我找到了我想要的东西。
默认情况下,ApplyFilter用于FilteredBindingList使用的包含,这就是为什么它将返回任何与结果匹配的内容。这很容易通过指定一个新的FilterProvider来补救。如果您需要一个示例,请参阅下面的代码。
Protected Sub Customers_SelectObject(Byval sender as Object, ByVal e As Csla.Web.SelectObjectArgs) Handles CustomerDataSource.SelectObject
Dim filteredList As New FilteredBindingList(Of CustomerOrders)(sortedList)
filteredList.FilterProvider = AddressOf CustomFilter
filteredList.ApplyFilter("CustomerID", CustomerName.SelectedValue)
e.BusinessObject = filteredList
End Sub
Private Function CustomFilter(item As Object, filter As Object) As Boolean
Dim result As Boolean = False
If item IsNot Nothing AndAlso filter IsNot Nothing Then
result = CStr(item).Equals(CStr(filter))
End If
Return result
End Function如您所见,代码非常相似,几乎不需要更改。
谢谢你们花时间研究了我的问题。
干杯,
安迪
https://stackoverflow.com/questions/32203516
复制相似问题