Home  »  Articles  »  ASP.Net  »

How to set filters in gridview?

 Posted By : Manoranjan SahooPosted Date : 30/10/2010 07:55:26 AM Category : ASP.Net Points : 3

We can set filters before binding the data to the gridview.

Follow the below steps :

1. Fetch data from database to dataset object

2. apply filter on the dataset. Then bind the data.

ex :


void SetFilter()
{
   DataSet ds=new DataSet();
   // you have to set the actual data here.
   string filters = "columnname = 'value'";
   ds.Tables[0].DefaultView.RowFilter = filters;
   if (ds.Tables[0].DefaultView.Count > 0)
   {
      GridView1.DataSource = ds.Tables[0].DefaultView;
      GridView1.DataBind();
   }
}


Thank You.

Responses
No responses found for this thread. Be the first to respond this thread.
Post Reply
Login to post Response.