Last post Nov 08, 2013 12:45 PM by Amit Birla
Oct 29, 2013 09:25 AM|Amit Birla|LINK
I am using custom paging in Asp.net webpage where in I am bringing only selected data rows (which is 10 rows) from Database out of total rows (which is lets say 1000) and binding with GridView and repeating the same for each page navigation within the GridView.
i have read some article and could do this. I could write the stored procedure which gives me specifc records. This stored procedure also returns total row count (1000) but I am not sure how to associate total row count (1000) with the GridView so that the
GridView starts showing me the page number on the pager at the bottom of the Gridview. some article says to store this value in ViewState but what to do next is not mentioned.
could someone please help me out and let me know how to associate Total Row Count to the Gridiew ?
Oct 29, 2013 10:20 AM|DarrellNorton|LINK
You have to display it on the page somewhere. The GridView does not have a TotalRowCount property.
You can output it like this (using ASPX markup):
Viewing page <%: pageIndex%> of <%: pageCount%> out of <%: rowCount%> rows.
If you want to store those in ViewState, put this in your page_load method:
pageCount = rowCount / pageSize;
ViewState["PageCount"] = pageCount;
ViewState["PageIndex"] = 0;
ViewState["RowCount"] = rowCount;
if (ViewState["PageIndex"] != null)
pageIndex = Convert.ToInt32(ViewState["PageIndex"]);
if (ViewState["PageCount"] != null)
pageCount = Convert.ToInt32(ViewState["PageCount"]);
if (ViewState["RowCount"] != null)
pageCount = Convert.ToInt32(ViewState["RowCount"]);
See the full code here: http://technico.qnownow.com/custom-paging-in-asp-net-gridview-control/
Oct 29, 2013 02:19 PM|prk_in|LINK
Here is the nice posts refer about how to use custome pageing in gridview
Oct 29, 2013 10:55 PM|l.laxmikant|LINK
If you are using Custom paging, I would suggest do not use any other paging functionality provided by GridView. Make GridView paging as false
and create new Pager line using ContentPlaceHolder
for more details see
how to use custom paging with asp.net Repeater or GridView
Nov 08, 2013 12:45 PM|Amit Birla|LINK
Thanks for the reply..
If we do not have to somehow bind it to GridView then why should we return it from database ? How does the gridview understand that Gridview has n number of pages ? and on what basis does Gridview display the page numbers in the pager section ?
Does GridView automatically shows number in the pager section (I can see the same in design view but not at runtime) ?