Link to home
Start Free TrialLog in
Avatar of hoyaabanks
hoyaabanks

asked on

GridView RowFilter?

How do you access and filter Gridview Data?  I have a gridview (gvRecords) setup on a page that is reading data from an object datasource (objData).  It currently selects all records in a data table.  I want to be able to filter the records for the Gridview in the code behind like so:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!User.Identity.IsAuthenticated() || !User.IsInRole("Administrator"))
        {
                   //Filter Gridview to show only records marked active???
                 
                   //What can I do to the gridview to apply a row filter?
                   GridView.RowFilter = "Active = 1";

                    //Or is there a way to get it from the Datasource?
                   objData.RowFilter = "Active = 1";

        }
    }
Avatar of Daniel Wilson
Daniel Wilson
Flag of United States of America image

GridView.RowFilter = "Active = 1";
 is correct.

After it, do
GridView.DataBind();
Sorry, that's not my code either ...


DataView dv = new DataView(MyDataSet);
dv.RowFilter = "Active = 1";
GridView.DataSource = dv;
GridView.DataBind();
ASKER CERTIFIED SOLUTION
Avatar of prairiedog
prairiedog
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In your case, replace ObjectDataSource1 with "objData":

DataView dv = (DataView)this.objData.Select();
dv.RowFilter = "Active=1";
GridView.DataSource = dv;
GridView.DataBind();