Count total rows of gridview with pagination

前端 未结 12 873
失恋的感觉
失恋的感觉 2020-12-03 12:02

I have a GridView with paging. When I try to count gridview row with gridview.rows.count, It gives me row count for current page only.

How can I get total rows of G

12条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 12:07

    Try below code

    int _TotalRecs = ((System.Data.DataView)GridView.DataSource).Count;
    int _CurrentRecStart = GridView.PageIndex * GridView.PageSize + 1;
    int _CurrentRecEnd = GridView.PageIndex * GridView.PageSize + GridView.Rows.Count;
    
    lblTitle.Text = string.Format("Displaying {0} to {1} of {2} records found", _CurrentRecStart, _CurrentRecEnd, _TotalRecs);
    

    For e.g. Output will be like below....

    Displaying 1 to 15 of 67 records found.

提交回复
热议问题