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
4182.41.13.1344/2/2020 1:48:21 PM925US
9234.136.192.2224/3/2020 3:23:21 PM322US
10103.45.137.14/1/2020 11:02:21 PM947US
1515.108.144.2394/2/2020 1:27:21 PM604US
1649.16.224.514/4/2020 10:38:21 AM939US
1867.212.149.1194/4/2020 5:46:21 AM269US
29237.82.136.524/3/2020 2:24:21 AM618US
3581.100.205.2364/2/2020 5:25:21 PM372US
39253.131.146.724/2/2020 5:36:21 PM859US
41178.102.28.324/2/2020 4:41:21 PM69US
44240.164.216.1574/2/2020 9:01:21 AM68US
5135.190.107.694/2/2020 11:51:21 PM617US
52209.205.17.2344/2/2020 11:03:21 PM887US
5855.96.113.2204/4/2020 4:47:21 AM83US
6020.80.2.324/3/2020 10:51:21 AM230US
72143.159.221.404/3/2020 9:37:21 AM141US
7332.112.118.174/3/2020 10:50:21 AM896US
74245.189.40.404/3/2020 5:58:21 PM484US
8023.209.213.254/2/2020 6:20:21 AM919US
84141.108.72.1934/4/2020 6:02:21 AM478US
8834.162.238.824/4/2020 4:36:21 AM286US
90231.87.212.2154/4/2020 12:35:21 PM610US
94178.73.205.744/4/2020 5:22:21 AM489US
95225.84.51.124/2/2020 6:32:21 PM459US
9978.153.22.994/2/2020 3:40:21 PM96US

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