Personal Blog of Mustafa Basgun

Enhancing Paging in ListView by Using DataPager

with 3 comments

DataPager is one of the new controls in ASP.NET 3.5, and it provides paging functionality for data-bound controls that implement the IPageableItemContainer interface, which is only the ListView control for the time being.

By default, DataPager has two commonly used paging styles:

• Numeric Pager via NumericPagerField

• Next and Previous Pager via NextPreviousPagerField

To get an idea about how to implement these basic common styles, you can read this post.

This post will explain how to enhance the paging experience in a ListView by using both a NextPreviousPagerField and a DropDownList which will enable users to select the page size of ListView. This page size is actually the PageSize property of the DataPager, and this property defines the number of records that are displayed for each page of ListView.

To avoid complexity, the following simple XML file (Contacts.xml) will be used as a data source:

And, the XMLDataSource that consumes this XML file is:

“xdsDemo” is the DataSourceID of the ListView “lvDemo”:

After getting this data binding done, LayoutTemplate of “lvDemo” should be similar to the following:

Even though it is not completely related with the topic and emphasis of this post, ItemTemplate and AltenatingItemTemplate templates of “lvDemo” are:

Finally, here is the code that sets DropDownList (ddlDemo) and DataPager (dpDemo):

As a conclusion of all these things, the result on the browser should be like:


Sample code for this demo application can be downloaded via here.


Written by Mustafa Basgun

May 7, 2008 at 10:30 AM

3 Responses

Subscribe to comments with RSS.

  1. It is great that ListView has pager and also dynamic page set.

    Vaibhav Kothia

    April 5, 2010 at 6:15 AM

  2. Can the ListView and DataPager be placed inside an UpdatePanel so that there will be no need for a full postback?


    – Tom


    July 27, 2010 at 2:20 AM

  3. I don’t see any reason not to.

    Mustafa Basgun

    July 30, 2010 at 10:23 PM

Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: