telerik radgrid custom pagination when total number of records is not known

2.3k Views Asked by At

I am using telerik radgrid in my .net aspx page. I want to implement custom pagination. But for this i don't have the total record count initially. Want to get more data from server when user clicks on the next page link after reaching the last page.

Example: if initially only 10 records are displayed on 1st page. If i click "Next" link it should fetch next set of data.

But issue is: "Next" button do not fire OnCommand or OnItemCommand events, if there are no more next pages.

So the question is how to handle pagination when total number of records is not knows initially? Which radgrid event to handle to get "Next" button click event irrespective of whether grid is already displaying last page or not.

1

There are 1 best solutions below

0
On

I didn't get any event which is fired on click of "Last Page" button when the grid is already on the last page.

So as a work around, i added a dummy page at the end. On click of the dummy page it will fetch next set of records from server.

For implementing custom pagination with RadGrid we do following things:
1. In aspx page add following attributes for RadGrid control
a. AllowPaging="true"
b. AllowCustomPaging="true"
c. VirtualItemCount = Total records on Server
2. In code behind, implement NeedDataSource event which gets data from server whenever required.

Here we do not know VirtualItemCount in advance. So I set the VirtualItemCount in OnPreRender() function of the page.
VirtualItemCount = no. of records in the grid + PageSize of RadGrid
This adds a dummy page at the end of the page numbers on the grid.

Get next set of data from server on click of the dummy page. Again the VirtualItemCount will be updated in OnPreRender() function as per the current no of records received from server and the pagesize.