ManuelAbadia.com
PagerDataSource samples
Samples



Product Information

Design-Time features

The PagerDataSource has rich design-time support to boost productivity. When a control is bound to the PagerDataSource in design-time, the PagerDataSource will expose schema information if its supported by the underlying data source. This means automatic template generation, automatic DataKeyField detection and fields lists when the PagerDataSource control is bound to a DataSourceControl that supports it. For example:


Design-time view

The PagerDataSource controls will display a preview of the control in design-time (as can be seen in the previous image) that will be updated as soon as the developer changes a property that affects the appearance of the control.

Updating the templates is easy with the design-time support for template editing as well as data binding support inside the templates as the next image shows:


Design-time view

The PagerDataSource also comes with several predefined formatting styles that can be applied to the control using the associated smart tag.

The source code for this page is shown after the live sample.


Product List

idnamedescriptionprice
1Product 1Full description for product number 12
2Product 2Full description for product number 24
3Product 3Full description for product number 36
4Product 4Full description for product number 48
5Product 5Full description for product number 510
6Product 6Full description for product number 612
7Product 7Full description for product number 714
8Product 8Full description for product number 816
9Product 9Full description for product number 918
10Product 10Full description for product number 1020
11Product 11Full description for product number 1122
12Product 12Full description for product number 1224
13Product 13Full description for product number 1326
14Product 14Full description for product number 1428
  • Page of 8

Sample source code

The ASPX file for this sample is:.


<%@ Page Language="C#" MasterPageFile="~/DefaultMaster.master" AutoEventWireup="true" CodeFile="DesignTime.aspx.cs" Inherits="DesignTime" Title="Design-Time Features" %>


<%
@ Register Assembly="PagerDataSource" Namespace="Manu.Web.UI.WebControls" TagPrefix="manu" %>

 

<asp:Content ID="Content1" ContentPlaceHolderID="Content" Runat="Server">

    <h2>Product List</h2>

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

        DataKeyNames="id" DataSourceID="PagerDataSource1">

        <Columns>

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

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

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

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

        </Columns>

    </asp:GridView>

   
    <manu:PagerDataSource ID="PagerDataSource1" runat="server"
        DataSourceID
="ObjectDataSource1" OnItemCommand="PagerDataSource1_ItemCommand"
        PageSize
="14" CssClass="pager" RenderMode="CSS">

        <PreviousPageTemplate>

           <asp:ImageButton ID="PreviousPage" runat="server" ImageUrl="images/prev.gif" />

        </PreviousPageTemplate>

        <LastPageTemplate>

            <asp:ImageButton ID="LastPage" runat="server" ImageUrl="images/last.gif" />

        </LastPageTemplate>

        <FirstPageTemplate>

            <asp:ImageButton ID="FirstPage" runat="server" ImageUrl="images/first.gif" />

        </FirstPageTemplate>

        <NextPageTemplate>

            <asp:ImageButton ID="NextPage" runat="server" ImageUrl="images/next.gif" />

        </NextPageTemplate>

        <SingleItemTemplate>

          Page

          <asp:TextBox ID="txtPage" runat="server" Text='<%# Eval("SelectedPageIndex") %>'

                Width="45px"></asp:TextBox>

            of

          <asp:Label ID="lTotalPages" runat="server" Text='<%# Eval("PageCount") %>'>
         </
asp:Label>

             <asp:ImageButton ID="Go" runat="server" CommandName="Go"
                ImageUrl
="images/go.gif" ValidationGroup="Go" />

            <asp:RequiredFieldValidator ID="rfvPage" runat="server"
                ControlToValidate
="txtPage" Display="Dynamic"

                ErrorMessage="Specify a page number" ValidationGroup="Go">

            </asp:RequiredFieldValidator>

            <asp:RangeValidator ID="RangeValidator1" runat="server"

                ControlToValidate="txtPage" Display="Dynamic"
                ErrorMessage="Page out of range" MaximumValue='<%# Eval("PageCount") %>'

                MinimumValue="1" Type="Integer" ValidationGroup="Go">

            </asp:RangeValidator>

        </SingleItemTemplate>

    </manu:PagerDataSource>

 

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

        SelectMethod="GetPagedData" SelectCountMethod="CountAll" EnablePaging="True"

        MaximumRowsParameterName="maxRows" StartRowIndexParameterName="startIndex">

    </asp:ObjectDataSource>

</asp:Content>


The code-behind file (ASPX.CS) is:


using System;

 

public partial class DesignTime : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

    }

 

    protected void PagerDataSource1_ItemCommand(object sender,PagerItemCommandEventArgs e)

    {

        if (e.CommandName == "Go") {

            TextBox txtPage = (TextBox)e.Item.FindControl("txtPage");

            if (txtPage != null) {

                int currentPage;

                if (Int32.TryParse(txtPage.Text, out currentPage)) {

                    e.Item.Owner.ChangePage(currentPage - 1);

                }

            }

        }

    }

}