ManuelAbadia.com
PagerDataSource samples
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
243.137.161.389/22/2018 10:50:50 PM137US
841.218.136.1609/22/2018 11:29:50 AM255US
22127.70.72.839/22/2018 2:03:50 AM132US
38179.159.90.79/22/2018 12:14:50 PM138US
4366.183.227.929/21/2018 10:55:50 PM930US
45243.49.107.2109/22/2018 3:19:50 AM587US
47193.8.3.1429/21/2018 4:20:50 PM29US
55122.87.89.1709/23/2018 12:12:50 AM453US
5621.156.125.2129/22/2018 11:44:50 PM60US
6068.132.23.2069/22/2018 1:32:50 AM771US
652.205.253.899/21/2018 10:22:50 PM196US
69164.77.1.219/22/2018 5:10:50 AM739US
70119.163.139.939/22/2018 2:55:50 PM639US
7135.187.189.1479/22/2018 1:42:50 AM535US
7272.79.157.109/22/2018 4:15:50 PM452US
8782.72.186.1279/22/2018 11:12:50 PM585US
9070.240.110.1809/21/2018 2:04:50 PM831US
915.11.148.1359/23/2018 4:02:50 PM788US
94156.87.251.1669/23/2018 1:48:50 AM917US
<<<|||||>>>

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">

    </manu:PagerDataSource>

 

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

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

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

        <Columns>

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

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

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

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

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

        </Columns>

        <RowStyle BackColor="White"

            ForeColor="#436799" />

        <HeaderStyle ForeColor="White" />

    </asp:GridView>

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

        DataSourceID="PagerDataSource1" UseCustomPageItems="True">

    </manu:PagerDataSource>

 

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

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

        MaximumRowsParameterName="maxRows" StartRowIndexParameterName="countryId" 
            OldValuesParameterFormatString
="original_{0}">

    </asp:ObjectDataSource>

</asp:Content>


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 Countries.codes) {

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

            }

 

            // set the custom page items for each PagerDataSource

            PagerDataSource1.CustomPageItems.AddRange(customPages);

            PagerDataSource2.CustomPageItems.AddRange(customPages);

        }

    }

}

sdafsdf