Neo
Neo

Reputation: 21

how to count no of records in gridview while paging is true

I have a gridview and in this grid i allow paging with page size 10. Now I want to find the total number of records on every page index. For example on page index 1 I have 10 records and on page index 2 I have 4 record so how do I count the number of record I just mentioned above?

Upvotes: 0

Views: 9505

Answers (2)

Andra Ciorici
Andra Ciorici

Reputation: 301

In case someone still searches for a solution to this problem, here it is:

DataView dv = (DataView)YourDataSource.Select(DataSourceSelectArguments.Empty);
int numberOfRows = int.Parse(dv.Table.Compute("Count(datakey)", "").ToString());

This also works if your datasource has a filtering expression, you just pass filter expression to the Compute method instead of "", like this

string rowFilter = YourDataSource.FilteringExpression;
int numberOfRows = int.Parse(dv.Table.Compute("Count(datakey)", rowFilter).ToString());

Upvotes: 3

Mikael Svenson
Mikael Svenson

Reputation: 39695

If gv is your gridview with paging:

var currentCount = (gv.PageIndex - 1) * gv.PageSize + gv.Rows.Count;

Upvotes: -1

Related Questions