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
8210.23.103.1413/25/2018 2:33:49 AM52US
1018.105.194.1973/25/2018 4:10:49 PM789US
13202.50.219.1433/24/2018 2:26:49 PM449US
1980.3.247.653/25/2018 8:57:49 AM295US
20175.221.228.2173/24/2018 5:24:49 PM636US
22118.37.155.493/23/2018 4:06:49 PM400US
24210.162.119.1693/24/2018 12:21:49 PM516US
25181.77.221.2483/25/2018 12:43:49 AM292US
2813.202.138.1083/24/2018 12:31:49 AM193US
367.225.246.2323/24/2018 5:20:49 PM316US
39156.241.252.1923/23/2018 1:08:49 PM691US
40209.230.238.2393/24/2018 10:05:49 PM356US
45196.189.69.1313/25/2018 2:43:49 AM65US
52253.89.43.1253/23/2018 8:21:49 PM196US
53227.141.137.613/24/2018 5:46:49 AM363US
55117.201.15.1343/23/2018 11:23:49 AM227US
6588.55.186.2383/24/2018 10:34:49 AM528US
66126.152.68.1153/25/2018 8:49:49 AM499US
8114.48.234.1863/25/2018 11:54:49 PM861US
85184.117.57.593/25/2018 7:37:49 PM543US
86157.214.72.163/23/2018 9:00:49 PM604US
8885.184.16.2413/23/2018 11:44:49 PM863US
9031.131.75.463/24/2018 8:36:49 PM166US
928.170.143.1493/24/2018 5:45:49 PM525US
95220.186.153.273/23/2018 6:05:49 PM533US

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