[英]Datatable -Row Filter using Windcard in asp.net c#
不要使用非常有限且過時的RowFilter
,但不要使用Linq-To-DataTable:
var matchingRows = from row in dt.AsEnumerable()
let roles = row.Field<string>("Role").Split('/')
where roles.Contains("5:4")
select row;
此方法首先用/
分割字符串,然后使用Contains
在此數組中搜索。
如果您需要知道是否存在匹配的行:
bool hasMatchingRows = matchingRows.Any();
如果要使用這些數學行創建一個新的DataTable:
if( hasMatchingRows )
{
DataTable tblMatches = matchingRows.CopyToDataTable();
}
如果您只想知道match.rows的初始列:
List<string> initials = matchingRows.Select(r => r.Field<string>("Initial")).ToList();
在此示例中僅包含NML
和GGRA
。
更換
dv1.RowFilter = "Role like'%5:4%'";
同
dv1.RowFilter = "Role like '5:4/%' OR Role like '%/5:4' OR Role = '5:4' OR Role like '%/5:4/%'";
// ^ ^ ^ ^
// startswith endswith equals contains
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.