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 2:36:06 PM46US
434.60.179.703/29/2017 12:48:06 PM635US
880.176.233.793/29/2017 4:39:06 AM503US
1065.251.228.353/29/2017 9:14:06 AM650US
16204.3.148.153/29/2017 5:12:06 PM629US
18185.74.192.2123/29/2017 10:19:06 PM129US
2336.198.243.383/30/2017 11:53:06 AM632US
29150.245.132.1493/29/2017 5:03:06 PM432US
43156.38.201.1983/30/2017 10:17:06 AM319US
4421.134.86.1663/29/2017 11:23:06 PM63US
5347.209.184.1503/30/2017 12:27:06 AM24US
57230.221.203.2393/28/2017 9:05:06 AM511US
64222.99.201.1963/30/2017 2:53:06 PM881US
6567.13.65.903/29/2017 9:30:06 AM745US
66148.6.3.1323/28/2017 3:21:06 AM356US
6918.84.198.2293/30/2017 5:32:06 PM345US
71239.237.6.1283/29/2017 2:08:06 AM619US
72234.74.4.343/30/2017 4:48:06 AM360US
75107.144.184.1213/30/2017 2:51:06 AM691US
771.218.56.843/30/2017 8:22:06 AM120US
96131.99.39.323/29/2017 5:22:06 AM985US

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