PagerDataSource samples

Product Information

Custom Page Items

In some scenarios we need to page the data source but not using a standard partition. For example, in a page with a list of customers, we may be interested to have a pager that contains all the letters, and when a letter is clicked, the customers whose name starts with that letter are shown.

The PagerDataSource has support for that scenario. In order to provide custom page items instead of the usual numbers, we have to set the UseCustomPageItems property to true and we also have to supply the custom page items using the CustomPageItems collection.

One implication of this mode is that each page of data can have any number of items and it is not limited by the PageSize. If we are using a DataSourceControl to supply the data to the PagerDataSource, it has to support paging and the startRowIndexParameter will contain the page item clicked (the maximumRowsParameter is not used in this case). If we are not using a DataSourceControl to supply the data to the PagerDataSource we can supply the data in the PageChanged event as the example Paging a DataSource (2) shows.

In this sample what we are going to use ficticious data showing IP addresses, access time and data downloaded. What we want is to populate the GridView with that data ( obtained from an ObjectDataSource) and let the user to see the data grouped by country. The PagerDataSource is used for this. In this sample, the custom page items are created in code, but they can be created also using the design-time editor.

The source code for this page is shown after the live sample.

IP addresses list

IdIPAddressConnectionTimeKB downloadedCountry
7227.190.154.1811/21/2018 3:33:28 AM867US
1598.65.51.251/21/2018 11:19:28 AM38US
1999.9.186.2351/22/2018 4:33:28 AM80US
23125.32.34.1271/20/2018 8:21:28 AM196US
2454.54.146.2521/20/2018 1:30:28 PM268US
25164.4.20.91/22/2018 12:15:28 AM761US
33245.85.158.831/22/2018 7:03:28 PM146US
36252.99.94.1831/22/2018 10:45:28 AM319US
3720.204.161.861/22/2018 4:11:28 AM209US
4248.117.65.1381/22/2018 3:30:28 PM680US
48242.247.174.2431/21/2018 12:34:28 PM208US
62133.95.67.901/21/2018 12:05:28 PM47US
64139.66.171.1191/20/2018 4:11:28 PM673US
69100.216.252.2041/21/2018 10:38:28 PM599US
74157.109.33.341/21/2018 9:12:28 AM282US
7534.32.203.421/22/2018 5:48:28 PM421US
7637.214.139.1241/22/2018 3:01:28 PM910US
78202.104.16.1231/20/2018 8:07:28 AM489US
80216.33.149.901/22/2018 11:11:28 AM562US
81116.19.20.2231/22/2018 5:07:28 AM303US
82244.167.131.171/20/2018 5:26:28 AM220US
86196.199.18.581/21/2018 11:12:28 AM69US

Sample source code

The ASPX file for this sample is:.

<%@ Page Language="C#" MasterPageFile="~/DefaultMaster.master" AutoEventWireup="true" CodeFile="CustomPageItems.aspx.cs" Inherits="CustomPageItems" Title="Custom Page Items" %>


<%@ Register Assembly="PagerDataSource" Namespace="Manu.Web.UI.WebControls" TagPrefix="manu" %>


<asp:Content ID="Content1" ContentPlaceHolderID="Content" Runat="Server">

    <h2>IP addresses list</h2>


    <manu:PagerDataSource ID="PagerDataSource1" runat="server"

        DataSourceID="ObjectDataSource1" UseCustomPageItems="True">



    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

        BorderColor="#133769" BorderStyle="Solid" BorderWidth="1px" DataKeyNames="Id"

        DataSourceID="PagerDataSource1" CssClass="gridview" AllowSorting="True">


            <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True"
="Id" />

            <asp:BoundField DataField="IPAddress" HeaderText="IPAddress" 
="IPAddress" />

            <asp:BoundField DataField="ConnectionTime" HeaderText="ConnectionTime"
="ConnectionTime" />

            <asp:BoundField DataField="KB downloaded" HeaderText="KB downloaded"
="KB downloaded" />

            <asp:BoundField DataField="Country" HeaderText="Country" 
="Country" />


        <RowStyle BackColor="White"

            ForeColor="#436799" />

        <HeaderStyle ForeColor="White" />


    <manu:PagerDataSource ID="PagerDataSource2" runat="server"

        DataSourceID="PagerDataSource1" UseCustomPageItems="True">



    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" TypeName="IPDataDAL"

        SortParameterName="sortedBy"  SelectMethod="GetDataByCountry" 
="CountAll" EnablePaging="True"

        MaximumRowsParameterName="maxRows" StartRowIndexParameterName="countryId" 



The code-behind file (ASPX.CS) is:

using System;

using System.Collections.Specialized;


public partial class CustomPageItems : System.Web.UI.Page


    protected void Page_Load(object sender, EventArgs e)


        // the first time, set the custom pages items

        if (!IsPostBack) {

            string image = "<img src='images/{0}.gif' />";


            StringCollection customPages = new StringCollection();


            // adds each image to the collection of custom page items

            foreach (string code in {

                customPages.Add(String.Format(image, code));



            // set the custom page items for each PagerDataSource