Mehmet
Mehmet

Reputation: 2288

Getting the count of all rows in a paged GridView control

I want to retrieve all rows count of Gridview.

When I try this

 GridView1.Rows.Count.ToString()

it returns only active page items count.

I m using generic list of my custom class as my GridView's data source .

How can I do this?

Upvotes: 0

Views: 3027

Answers (2)

Daniel Dyson
Daniel Dyson

Reputation: 13230

I think you should try @Tim's suggestion first as it is a better answer (he just got in before me) with it, but you can also use the Selected event of the ObjectDataSource to do this...

protected void ObjectDataSource_Selected(object sender,
ObjectDataSourceStatusEventArgs e)
{

      //if ReturnValue is a List - you might need to change this in your case.
      var list = (List<Lib.User>)e.ReturnValue;
      Response.Write(list.Count.ToString());
 }

Upvotes: 0

Tim Schmelter
Tim Schmelter

Reputation: 460158

Access your generic list's Count Property on databinding. Where/why do you need the total row count?

According to your new information on ObjectDataSource: Have a look at the ObjectDataSource.Selected Event

And on this example: http://www.webswapp.com/categories/ViewSourceCode.aspx?id=ASPNET20DDLinGridViewC-GridView

Upvotes: 3

Related Questions