Home > ASP.Net > Custom Paging with the ASP.NET Repeater

Custom Paging with the ASP.NET Repeater

Unlike DataGrid or GridView control, Repeater does not provide the facility for paging. If we need to show large amount of data and also want to utilize the flexibility of Repeater control, we will have to do some kind of custom paging.

Recently, i had to use paging with ASP.NET Repeater Control. Following URLs helped me in doing so:


These URLs gave me a basic idea on how to do it with Repeater. Difference in my project was that i was not using LINQ so use of Skip() or Take() methods was not possible. I was getting Results (in data-table) using SQLCommand. To resolve this issue, i used the ROW_NUMBER clause provided in SQL Server 2005 onwards. By using ROW_NUMBER() we can easily fetch page wise data. Following is one of the sample queries i used to bind Repeater Control:

/*You can pass these as parameter>>*/
DECLARE @PageIndex AS INT /*Current Page Index (1-based index)*/
DECLARE @PageSize AS INT /*Number of records per page*/
SET @PageSize = 10
SET @PageIndex = 3
/*You can pass these as parameter<<*/

DECLARE @PageStartIndex AS INT
SET @PageStartIndex = ((@PageIndex-1) * @PageSize) + 1
/*Select Page Start Index Based on Current Page*/

SELECT TOP (@PageSize) * FROM (SELECT ROW_NUMBER()  OVER (ORDER BY ItemID) AS RowNum, * FROM HtmlText) AS SelectTable WHERE RowNum >= @PageStartIndex

This query will provide result set based on current page.

Categories: ASP.Net Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: