Fork me on GitHub

AspNetPager demo - Customize navigation buttons

This sample demonstrates how to customize the text format of navigation buttons.

Order ID: 11074     Order Date: 5/6/1998
Company Name: Simons bistro
Employee Name: Robert King

Order ID: 11075     Order Date: 5/6/1998
Company Name: Richter Supermarkt
Employee Name: Laura Callahan

Order ID: 11076     Order Date: 5/6/1998
Company Name: Bon app'
Employee Name: Margaret Peacock

Order ID: 11077     Order Date: 5/6/1998
Company Name: Rattlesnake Canyon Grocery
Employee Name: Nancy Davolio

Order ID: 11070     Order Date: 5/5/1998
Company Name: Lehmanns Marktstand
Employee Name: Andrew Fuller

Order ID: 11071     Order Date: 5/5/1998
Company Name: LILA-Supermercado
Employee Name: Nancy Davolio

Order ID: 11072     Order Date: 5/5/1998
Company Name: Ernst Handel
Employee Name: Margaret Peacock

Order ID: 11073     Order Date: 5/5/1998
Company Name: Pericles Comidas clásicas
Employee Name: Andrew Fuller

Order ID: 11067     Order Date: 5/4/1998
Company Name: Drachenblut Delikatessen
Employee Name: Nancy Davolio

Order ID: 11068     Order Date: 5/4/1998
Company Name: Queen Cozinha
Employee Name: Laura Callahan

ButtonsFormat.aspx:

<p><asp:Label runat="server" ID="label1" ForeColor="red" EnableViewState="false"></asp:Label>
<br /><asp:Label runat="server" ID="label2" ForeColor="red" EnableViewState="false"></asp:Label></p>
    <asp:CheckBox ID="CheckBox1" runat="server" Text="Cancel Paging" />��check this checkbox will only fire PageChanging event, PageChanged event will not be triggered��
    <p>AspNetPager running affect:</p>
    <webdiyer:aspnetpager id="AspNetPager1" runat="server" onpagechanged="AspNetPager1_PageChanged" 
    Width="100%" HorizontalAlign="center" AlwaysShowFirstLastPageNumber="true" PagingButtonSpacing="10"></webdiyer:aspnetpager>

    <p>Cloned AspNetPager:</p>
    <div><webdiyer:aspnetpager id="AspNetPager2" runat="server" CloneFrom="AspNetPager1"></webdiyer:aspnetpager></div>

ButtonsFormat.aspx.cs:

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;

public partial class ButtonsFormat_Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int totalOrders = (int)SqlHelper.ExecuteScalar(CommandType.StoredProcedure, "P_GetOrderNumber");
            AspNetPager1.RecordCount = totalOrders;
            bindData();
        }
    }

    void bindData()
    {
        DataList1.DataSource = SqlHelper.ExecuteReader(CommandType.StoredProcedure, ConfigurationManager.AppSettings["pagedSPName"],
            new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
            new SqlParameter("@endIndex", AspNetPager1.EndRecordIndex));
        DataList1.DataBind();
    }
    protected void AspNetPager1_PageChanged(object src, EventArgs e)
    {
        bindData();
    }
}