The PagerDataSource performs two main tasks:
- Retrieve data from a data source and expose it to another control, performing paging
- Provide a customized user interface to allow navigation to the different pages
To retrieve data from the data source, the PagerDataSource can use any of the two
options that the ASP.NET framework gives us:
- Using the DataSource property: the only option available in ASP.NET 1.x.
- Using the DataSourceID property: using the new ASP.NET 2.0
DataSourceControls, and without writing a single line of code!.
The PagerDataSource control has two working modes:
- Extracting the data for the current page from the data source.
- Requesting the data for the current page only.
Take a look at the Live Demos for examples about the different options of data sources
and working modes.
A key requirement for a pager is customization. The PagerDataSource provides unlimited
customization capabilities. Most users will need to configure a few properties to
achieve the look they want. The most exigent users will use the templates to achieve
Some times we have the necessity to use two pagers in a page to provide better navigation.
For example, one above a list of data and the other below the data. When the user clicks in one pager, we have to update the data that is shown between the pagers
and maintain the pagers synchronized. You will be surprised to see how you can link
PagerDataSource controls and have them synchronized with no code
CSS Lists support
By default, the PagerDataSource renders itself as an HTML table.
However, with the advent of the Web 2.0, many developers prefer to work with CSS
Lists instead of tables. The PagerDataSource can render itself
as HTML unordered lists that can be easily customized using CSS changing only one
property at design time!
Search Engine Optimization
The ASP.NET programming model is not ideal for search engine spiders. The ASP.NET
of a site is exposed to search engines with all the benefits that are lost because
The PagerDataSource can work in postback mode and also using the
query string, so search engines can index your site if you are using the query string
A better solution to optimize search engine exposure is to rewrite the URLs of
the site to avoid passing parameters using the query string. The PagerDataSource
has support for customizing the generated URLs as it is shown in a sample where
friendly URLs are used.
Custom page items
By default, the PagerDataSource renders each page link as a number.
However, in some scenarios it is better to partition the data in a non standard way, like
showing the results by month. The pager can display a list of all the months and the
data presented to the user is the data from the currently selected month. The
PagerDataSource can handle this scenario easily and in some cases,
without writing a single line of code!
Two steps are needed to use the PagerDataSource control
with a DataSourceControl:
- set the DataSourceID property of the PagerDataSource to the ID
of a DataSourceControl.
- set the DataSourceID property of the control that will be paged by the PagerDataSource
to the ID of the PagerDataSource.
The DataSourceControls introduced in ASP.NET 2.0 help to improve productivity exposing
type information and showing configuration wizards in design-time.
It would be a shame that when
you connect the PagerDataSource control
to the control that will receive the paged data you lost the design-time functionality
of the underlying DataSourceControl (the one that provides the
data to the PagerDataSource). Fortunately the PagerDataSource
exposes the design-time information and the wizard of the underlying DataSourceControl:
Also, the PagerDataSource control supports inserting, updating or deleting data if the underlying DataSourceControl supports it.
If you want to see the PagerDataSource control in action as well as see samples
and read more about the features of the control, be sure to visit the Live Demo