Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this code:

C#
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?
Posted

1 solution

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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900