我使用datagridview绑定到datatable来显示我的记录,我有这样的记录(只是示例)
名称 国家/地区 城市
JAck Country1 City1
Name2 Country1 City2
JACK Country2 City1
我有搜索文本框我不想使用此文本框在此datagridview中搜索多个关键字
我不想获得Country1的所有记录并拥有名称杰克
我在这个文本框中放了一个字符串
[JACK country1]
我创建此方法以基于任何列
string query = "";
Boolean firsttime = true;
bool firstkeyword = true;
foreach (string se in txt_ar_recherche.Text.Trim().Split(' '))
{
string search = (Convert.ToString(" like '%") + se) + "%'";
if(!firstkeyword) query += " and ";
query += "(";
bool firstcolumn = true;
foreach (DataGridViewColumn col in grid.Columns)
{
if (col.Visible)
{
if (firsttime)
{
query += "Convert(" + col.Name + ",'System.String')" + search;
firsttime = false;
}
else
{
query += " or " + "Convert(" + col.Name + ",'System.String')" + search;
}
}
firstcolumn = false;
}
firstkeyword = false;
query += ")";
}
(grid.DataSource as DataTable).DefaultView.RowFilter = query;
但它无法正常工作我不知道如何解决此问题,以便在datagridview中使用mutilple关键字进行搜索 我不想创建数据表javascript使用的相同文本框搜索,这是一个演示https://datatables.net/
答案 0 :(得分:1)
试试这个完整的样本:
ngOnInit() {
//this.myId = this.route.snapshot.params['myId'];
this.route.params.subscribe(params => {
this.myId = params['myId'];
});
}