This is a migrated thread and some comments may be shown as answers.

Binding to a filtered DataTable

1 Answer 24 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 21 Jan 2009, 04:06 PM
If I apply a FilterExpression to a DataTable's DefaultView, if I want to see only the filtered rows in my grid should I bind to DataTable.DefaultView or can I just bind to the DataTable and get the same result?

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 22 Jan 2009, 05:06 AM
Hi Rob,

Since you are setting the filter expression to the DataTable's DefaultView you can bind the DefultView as the DataSource for the Grid to show the filtered data in Grid.

CS:
            conn.Open(); 
            string selectQuery = "SELECT ProductID,ProductName,SupplierID FROM Products"
            adp.SelectCommand = new SqlCommand(selectQuery, conn); 
            DataTable dtTable = new DataTable(); 
            adp.Fill(dtTable); 
            DataView dv = dtTable.DefaultView; 
            dv.RowFilter = "ProductName='Aniseed '"
            RadGrid1.DataSource = dv; 
            conn.Close(); 


Thanks
Shinu.
Tags
Grid
Asked by
Rob
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or