使用List <string>或string []过滤DataView

时间:2017-03-24 06:16:54

标签: .net generics c#-4.0 dataview

我想在dataview上应用rowfilter,它应该在List上运行。下面是我到目前为止写的代码没有运气。

  

使用&lt; %%&gt;获取所有标记来自源字符串的符号

string src = "<%Borrower Name%>|<%Dealer Number%>|<%Application Number%>|【<%Asset Make Description%>】尊敬的经销商:您提交的编号<%Application Number%>客户<%Borrower Name%>的申请已拒绝。";

MatchCollection matches = Regex.Matches(src, @"\<%([^%>]*)\%>");

List<string> lstnew = matches.Cast<Match>().Select(x => x.Value).ToList();

DataSet dstokens = new DataSet();

ReadTokensData(dstokens, null);
  

这里是过滤部分,我想基于过滤数据表   对于列表中的值,使用string []执行此操作对我来说也是可以接受的

dstokens.Tables["TOKENS_DATA"].DefaultView.RowFilter = "TOKEN_CAPTION IN (" + lstnew + ")";

2 个答案:

答案 0 :(得分:0)

试一试

假设dtAllUsers数据表中包含数据。我们可以从dtAllUsers的数据表中过滤数据如下。

UserName = DataTable的要搜索的列

txt_SearchByUser.Text =您要在UserName列中搜索的文本

dgv_All_Users =是DataGridView

DataView DV = new DataView(dtAllUsers);

DV.RowFilter = string.Format("UserName Like '%{0}%'",txt_SearchByUser.Text);

dgv_All_Users.DataSource = DV;

答案 1 :(得分:0)

分解你的代码,结果为;

app/code/namespace/modulename

你想要的地方

WHERE TOEKN_CAPTION IN (<%BorrowerName%>,<%DealerNumber%>,<%AppNumber%>,etc)

将您的Linq语句更改为以下

WHERE TOEKN_CAPTION IN ('BorrowerName','DealerNumber','AppNumber',etc)
相关问题