Fork me on GitHub

AspNetPager demo - N tier application

This sample demonstrate how to use AspNetPager control in a N tier application.

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

<<<<1><2><3><4><5><6><7><8><9><10>...>>>  

NTier.aspx:

    <asp:DataList ID="DataList1" runat="server" Width="100%"  RepeatDirection="Horizontal" RepeatColumns="2">
        <ItemStyle Width="50%"/>
<ItemTemplate>
Order ID: <%#DataBinder.Eval(Container.DataItem,"orderid")%>    
Order Date: <font color="red"><%#DataBinder.Eval(Container.DataItem,"orderdate","{0:d}")%></font><br>
Company Name: <%#DataBinder.Eval(Container.DataItem,"companyname")%><br>
Employee Name: <%#DataBinder.Eval(Container.DataItem,"employeename")%><br>
<hr>
</ItemTemplate>
    </asp:DataList>
    <webdiyer:AspNetPager ID="AspNetPager1" runat="server" HorizontalAlign="Center" Width="100%" PageIndexBoxType="DropDownList" OnPageChanged="AspNetPager1_PageChanged" NumericButtonTextFormatString="<{0}>">
    </webdiyer:AspNetPager>

NTier.aspx.cs:

using System;
using System.Collections.Generic;
using System.Web.UI;

public partial class NTier_Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            AspNetPager1.RecordCount = OrderInfo.GetOrderCount();
            bindData();
        }
    }

    void bindData()
    {
        List<OrderObject> orders = OrderInfo.GetPagedOrders(AspNetPager1.StartRecordIndex, AspNetPager1.PageSize);
        DataList1.DataSource = orders;
        DataList1.DataBind();
    }

    protected void AspNetPager1_PageChanged(object src, EventArgs e)
    {
        bindData();
    }
}