Solved

GridView RowFilter?

Posted on 2008-10-06
4
2,144 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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