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?
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());
如果gv是带分页的gridview:
var currentCount = (gv.PageIndex - 1) * gv.PageSize + gv.Rows.Count;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.