Thursday, May 10, 2007

Paging in repeater control

By default repeater control does not have paging capability. To have that we can use PagedDataSource Class. Using PagedDataSource class it is easy to have paging capability in repeater control. Following are the steps to have this functionality:

1. Create object instance of PagedDataSource class (The class can be found in System.Web.UI.WebControls namespace

2. Assign your data to DataSource property of PagedDataSource object.

3. Set the paging properties of PagedDataSource object. The properties may include AllowPaging, PageSize etc.

4. You may like to set the current page index using CurrentPageIndex property of PagedDataSource object.

5. IsFirstPage/IsLastPage properties can be used to take care of disabling/enabling navigation buttons.

6. Assign the PagedDataSource object to DataSource property of Repeater control.

7. Call the DataBind() method of Repeater control.

8. For page navigation you need to have your own link or buttons.

Hope this helps you!!!

1 comment: