Fork me on GitHub

UrlPager Demo - Paging for repeater

This sample demonstrates how to use UrlPager control to add paging functionality to the Repeater control.
Order IDOrder DateCompany NameCustomer IDEmployee Name
11074 5/6/1998 Simons bistro SIMOB Robert King
11075 5/6/1998 Richter Supermarkt RICSU Laura Callahan
11076 5/6/1998 Bon app' BONAP Margaret Peacock
11077 5/6/1998 Rattlesnake Canyon Grocery RATTC Nancy Davolio
11070 5/5/1998 Lehmanns Marktstand LEHMS Andrew Fuller
11071 5/5/1998 LILA-Supermercado LILAS Nancy Davolio
11072 5/5/1998 Ernst Handel ERNSH Margaret Peacock
11073 5/5/1998 Pericles Comidas clásicas PERIC Andrew Fuller
11067 5/4/1998 Drachenblut Delikatessen DRACD Nancy Davolio
11068 5/4/1998 Queen Cozinha QUEEN Laura Callahan
 First Prev 1 2 3 4 5 6 7 8 9 10 ... Next Last

Route definition:

     routes.MapPageRoute("UrlPager_Repeater",
                "urlpager/demos/{controller}/{action}/{id}",
                "~/UrlPager/Demos/Repeater.aspx", false, new RouteValueDictionary { { "controller", "Repeater" }, { "action", "Page" }, { "id", null } }, new RouteValueDictionary { { "controller", "Repeater" }, { "action", "Page" } });
   

Repeater.aspx:

 <%@Register Namespace="Webdiyer.WebControls" Assembly="Webdiyer.UrlPager" TagPrefix="webdiyer"%>
<asp:Repeater ID="Repeater1" runat="server">
     <headertemplate>
     <table class="table table-bordered table-hover">
     <tr><th>Order ID</th><th>Order Date</th><th>Company Name</th><th>Customer ID</th><th>Employee Name</th></tr>
        </headertemplate>
     <itemtemplate>
     <tr>
     <td><%#DataBinder.Eval(Container.DataItem,"orderid")%></td>
     <td><%#DataBinder.Eval(Container.DataItem,"orderdate","{0:d}")%></td>
     <td><%#DataBinder.Eval(Container.DataItem, "companyname")%></td>
     <td><%#DataBinder.Eval(Container.DataItem,"customerid")%></td>
     <td><%#DataBinder.Eval(Container.DataItem,"employeename")%></td>
        </tr>
        </itemtemplate>
     <footertemplate>
        </table>
        </footertemplate>
        </asp:Repeater>
     <webdiyer:UrlPager runat="server" id="pager1" RouteName="UrlPager_Repeater" CssClass="pull-right" PageIndexParameterName="id" PagerItemTemplate="&nbsp;{0}"
                        OnPageChanged="PageChanged"></webdiyer:UrlPager> 
 

Repeater.aspx.cs:

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace Webdiyer.UrlPagerDemo
{
    public partial class Repeater : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                pager1.TotalItemCount = (int)SqlHelper.ExecuteScalar(CommandType.StoredProcedure, "P_GetOrderNumber");
        }
        protected void PageChanged(object sender, EventArgs e)
        {
            Repeater1.DataSource = SqlHelper.ExecuteReader(CommandType.StoredProcedure, ConfigurationManager.AppSettings["pagedSPName"],
                new SqlParameter("@startIndex", pager1.StartItemIndex),
                new SqlParameter("@endIndex", pager1.EndItemIndex));
            Repeater1.DataBind();
        }
    }
}