如何从网格视图的多列搜索 [英] How to Search from Grid View's Multiple Column

查看:52
本文介绍了如何从网格视图的多列搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从gridview的更多栏目中搜索

我的代码是

I want to search from more column of gridview
my code is

private void SearchText(string strSearchText)
            {
                DataTable dt = dtBindGrid();
                DataView dv = new DataView(dt);
                dv.RowFilter = "FNAME like '%" + strSearchText + "%'";
                dv.RowFilter = "LASTNAME like '%" + strSearchText + "%'";
                gridView1.DataSource = dv;
                gridView1.DataBind();

            }



但它不起作用。它只从Last Name Column中搜索。

我也想从FNAME和LASTNAME中搜索。


But it not working. it only search from Last Name Column Only.
I want to Search From FNAME and LASTNAME too.

推荐答案

设置dv.RowFilter两次不会工作。第二个状态将覆盖之前的 dv.RowFilter 设置。



点击此处 DataView RowFilter语法[C#] [ ^ ]了解更多过滤格式和条件。



在您的情况下,您必须使用 AND 连词来过滤两个字段

例如:

setting dv.RowFilter two times wont work. the second state will overwrite the previous dv.RowFilter settings.

Check here DataView RowFilter Syntax [C#][^] for more Filter formats and conditions.

In your case you must use AND conjunction to filter by two fields
eg:
// operator AND has precedence over OR operator, parenthesis are needed
dataView.RowFilter = "City = 'Tokyo' AND (Age < 20 OR Age > 60)";

// following examples do the same
dataView.RowFilter = "City <> 'Tokyo' AND City <> 'Paris'";
dataView.RowFilter = "NOT City = 'Tokyo' AND NOT City = 'Paris'";
dataView.RowFilter = "NOT (City = 'Tokyo' OR City = 'Paris')";
dataView.RowFilter = "City NOT IN ('Tokyo', 'Paris')";



请记住上面的每一个都是不同的例子,你应该只使用一个 RowFilter 赋值。


另一个解决方案是在您从dtBindGrid()获取的数据表上使用LINQ并过滤掉这些值,最后绑定它。
one more solution is to use LINQ over the datatable that you are getting from the dtBindGrid() and filter out the values and finally bind that.


这篇关于如何从网格视图的多列搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆