Thursday, December 23, 2010

.NET - Custom paging in grid view


Introduction:

Grid view control’s inbuilt paging  mechanism proves to be performance degrading because we will be retrieving all the records in the database regardless of the page size(10 or 20)  we are showing in the aspx page. A custom paging technique should be used instead of inbuilt paging.


Description:

Custom paging allows us to retrieve only that 10 or 20 records which are being shown on the page.  The following sql  query retrieves only the requested number of records.

Rounded Rectangle: SELECT RowNum, EmployeeID, LastName, FirstName
FROM
   (SELECT EmployeeID, LastName, FirstName 
       ROW_NUMBER() OVER(ORDER BY EmployeeID) as RowNum
       FROM Employees e
   ) as EmployeeInfo