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
11108.38.166.5410/27/2017 7:47:20 AM398US
14236.57.223.8710/25/2017 8:10:20 AM76US
1856.129.171.17710/27/2017 5:56:20 AM929US
3383.30.107.14710/27/2017 5:29:20 AM774US
56111.92.139.5010/26/2017 2:59:20 AM449US
63148.217.196.5110/27/2017 1:51:20 AM811US
7686.94.66.10210/27/2017 12:31:20 PM39US
8417.39.40.22910/27/2017 7:59:20 AM140US
8799.179.53.23510/25/2017 7:14:20 PM608US
94170.72.90.22210/25/2017 8:53:20 AM550US
95140.202.28.5810/27/2017 4:19:20 PM156US
97191.236.187.14910/26/2017 4:00:20 AM406US
9893.200.246.4110/27/2017 9:32:20 AM132US
<<<|||||>>>

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