在不使用数据集的情况下过滤datagridview [英] Filtering datagridview without using dataset

查看:81
本文介绍了在不使用数据集的情况下过滤datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码:

I have this code:

protected void Page_Load(object sender, EventArgs e)
       {
           DataTable dt = GetTable();

           dt2.DataSource = dt;
           dt2.DataBind();

           ddl.DataSource = dt;
           ddl.DataTextField = "Author";
           ddl.DataValueField = "Author";
           ddl.DataBind();
           ddl.Items.Insert(0, "All");
        }


       static DataTable GetTable()
       {
           DataColumn col = new DataColumn();

           DataTable table = new DataTable();
           table.Columns.Add("ISBN",typeof(string));
           table.Columns.Add("Name",typeof(string));
           table.Columns.Add("Author",typeof(string));
           table.Columns.Add("Year",typeof(string));

           table.Rows.Add("9780471678403", "Acoustic Echo and Noise Control", "Hansler", "2000");
           table.Rows.Add("9780470544068", "Active Antennas and Quasi-Optical Arrays", "Tsoulus", "2001");
           table.Rows.Add("9780470396360", "Algorithms and Protocols for wireless Sensor Networks", "Boukerche", "2002");

           col = table.Columns["Author"];

           return table;


       }



这是一个简单的示例,但是我需要过滤数据,而我在互联网上寻找的所有示例都包括数据集和人员.
如果我放了一个下拉列表,只需要向我显示我选择的作者,那么我无法使用这种类型的代码来做到这一点吗?



it is a simple example, but i need to filter the data and all the examples i looked for ont he internet all included dataset and staff.
If i put a drop down list, having to show me only the authors which i choose, i cannot do it with this type of code? Do i have to use datasets for sure?

推荐答案

只能在数据源上进行过滤,因此可以使用bindingsource或绑定的数据表到datagridview.该链接具有多种过滤datagridview的方法,但都使用某些或其他表单绑定源:
http://social.msdn.microsoft.com/Forums/eu/vblanguage/thread/dced49a7-7b37-4fc0-a829-5b5ba4520742 [
Filtering can be done on the data source only, so you can either use a bindingsource or the data table that is bound to datagridview. This link has plenty of ways to filter a datagridview but all use some or the other form binding source:
http://social.msdn.microsoft.com/Forums/eu/vblanguage/thread/dced49a7-7b37-4fc0-a829-5b5ba4520742[^]


这篇关于在不使用数据集的情况下过滤datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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