Hire my services

If you would like to hire my services, you can now do so by visiting the following link:

Website Design Darlington

Article Statistics

ArticlesLatest Entry
2121-May-2008

Code Bank Statistics

CategoryTipsLatest Entry
Applications420-Feb-2008
Cache118-Apr-2007
Controls926-Jul-2007
CSS107-Sep-2007
Database428-Aug-2007
Dates128-Aug-2007
Email105-Mar-2007
Files123-Apr-2007
HTML101-Mar-2007
Images226-Mar-2007
Pages115-Oct-2007
Sessions122-Nov-2007
SQL Server1518-Mar-2008
Strings309-May-2007
Skip Navigation LinksHome > Articles > Add paging to a repeater

Add paging to a repeater

Summary: An example of how we can add paging to a repeater control by using a PagedDataSource.Socialize it

Data controls such as the GridView have built in support for paging, however this isn't the same for the Repeater control. To add this functionality, I've decided to use the PagedDataSource class.

Let's start by creating a simple page which just contains a Repeater:

Then, we'll populate this page with some sample data:

As you'll see from the output, we have some sample data written out to the page ranging from items 0 to 10. Now, to add the paging capabilities we can use the PagedDataSource. To do this, we'll amend the GetData() function to return a PagedDataSource and we'll add a DataView from the current DataTable to it. e.g.

If we ran this code now, we wouldn't actually see a difference in the results since we haven't actually set a page size yet. However, before we do this, we'll add some navigation links and a label to our page so we can see what page we are on and also be able to navigate to each page. Just under the Repeater control, add these controls:

Now, we need to actually apply the functionality that will allow the Repeater to be paged. To do this, we'll use querystring values to determine which page we need to show and also set a default just in case this page doesn't exist. Then, we can set the relevant page by setting the CurrentPageIndex property of our PagedDataSource and then rebind the grid. I've added comments to each section of the code so you should be able to see what steps we are taking along the way so let's go ahead and replace our current code with the new code that applies this functionality:

When we run this code, you'll now see that we now have 6 pages (since we set the page size to 2 in this example) and that you can navigate to each page by using the Previous/Next links.

Reader Comments

1. Dimitar Voynov 07/06/2007 00:09:28

2. Kooshal 08/01/2008 21:05:13

3. ishwor 21/07/2008 02:07:28

Add your comments

Please keep your comments relevant to this page. Any inappropriate or purely promotional comments may be removed. Email addresses are never displayed but are required so you can confirm your comments.

Your Name:
 
Your Email:
 
Add your comments: