Fork me on GitHub

AspNetPager demo - Using table layout

This sample demonstrates how to use table layout with the AspNetPager control.

Order IDOrder DateCompany NameEmployee Name
108962/19/1998Maison DeweyRobert King
108972/19/1998Hungry Owl All-Night GrocersJanet Leverling
108932/18/1998K?niglich EssenAnne Dodsworth
108942/18/1998Save-a-lot MarketsNancy Davolio
108952/18/1998Ernst HandelJanet Leverling
108912/17/1998Lehmanns MarktstandRobert King
108922/17/1998Maison DeweyMargaret Peacock
108882/16/1998Godos Cocina TípicaNancy Davolio
108892/16/1998Rattlesnake Canyon GroceryAnne Dodsworth
108902/16/1998Du monde entierRobert King
<<<...11121314151617181920...>>>  Page:19 of 32,10 per page

TableLayout.aspx:

  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%" CssClass="table table-bordered">
            <Columns>
                <asp:BoundField DataField="orderid" HeaderText="Order ID" />
                <asp:BoundField DataField="orderdate" HeaderText="Order Date" DataFormatString="{0:d}" />
                <asp:BoundField DataField="companyname" HeaderText="Company Name" />
                <asp:BoundField DataField="employeename" HeaderText="Employee Name" />
            </Columns>
        </asp:GridView>
        <webdiyer:AspNetPager id="AspNetPager1" runat="server" PagingButtonSpacing="8px" onpagechanged="AspNetPager1_PageChanged"
            showcustominfosection="Right" CustomInfoHTML="Page:<font color='red'><b>%currentPageIndex%</b></font> of %PageCount%,%PageSize% per page" urlpaging="True" width="100%" LayoutType="Table" ShowNavigationToolTip="true" UrlPageIndexName="pageindex"></webdiyer:AspNetPager>
        

TableLayout.aspx.cs:

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

public partial class TableLayout_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //cache the number of total records to improve performance
            object obj = Cache[GetType() + "totalOrders"];
            if (obj == null)
            {
                int totalOrders = (int)SqlHelper.ExecuteScalar(CommandType.StoredProcedure, "P_GetOrderNumber");
                Cache[GetType() + "totalOrders"] = totalOrders;
                AspNetPager1.RecordCount = totalOrders;
            }
            else
            {
                AspNetPager1.RecordCount = (int)obj;
            }
        }
    }


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