?
Solved

GridView RowFilter?

Posted on 2008-10-06
4
Medium Priority
?
2,182 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

830 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