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.IsAuthenti cated() || !User.IsInRole("Administra tor"))
{
//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";
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!User.Identity.IsAuthenti
{
//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";
}
}
Sorry, that's not my code either ...
DataView dv = new DataView(MyDataSet);
dv.RowFilter = "Active = 1";
GridView.DataSource = dv;
GridView.DataBind();
DataView dv = new DataView(MyDataSet);
dv.RowFilter = "Active = 1";
GridView.DataSource = dv;
GridView.DataBind();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In your case, replace ObjectDataSource1 with "objData":
DataView dv = (DataView)this.objData.Sel ect();
dv.RowFilter = "Active=1";
GridView.DataSource = dv;
GridView.DataBind();
DataView dv = (DataView)this.objData.Sel
dv.RowFilter = "Active=1";
GridView.DataSource = dv;
GridView.DataBind();
is correct.
After it, do
GridView.DataBind();