?
Solved

GridView RowFilter?

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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 …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

771 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