Solved

GridView RowFilter?

Posted on 2008-10-06
4
2,127 Views
Last Modified: 2013-12-17
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";

        }
    }
0
Comment
Question by:hoyaabanks
  • 2
  • 2
4 Comments
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 22651761
GridView.RowFilter = "Active = 1";
 is correct.

After it, do
GridView.DataBind();
0
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 22651785
Sorry, that's not my code either ...


DataView dv = new DataView(MyDataSet);
dv.RowFilter = "Active = 1";
GridView.DataSource = dv;
GridView.DataBind();
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 500 total points
ID: 22651843
There is no "RowFilter" for GridView control.
Try this:
DataView dv = (DataView)this.ObjectDataSource1.Select();
dv.RowFilter = "Active=1";
GridView.DataSource = dv;
GridView.DataBind();
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22651856
In your case, replace ObjectDataSource1 with "objData":

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now