Reputation: 21
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
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
Reputation: 39695
If gv is your gridview with paging:
var currentCount = (gv.PageIndex - 1) * gv.PageSize + gv.Rows.Count;
Upvotes: -1