Fork me on GitHub

UrlPager 示例 - Repeater分页

本示例演示如何使用UrlPager分页控件对Repeater控件进行分页,使用的路由名为“UrlPager_Repeater”。
Order IDOrder DateCompany NameCustomer IDEmployee Name
10837 1998/1/16 Berglunds snabbköp BERGS Anne Dodsworth
10836 1998/1/16 Ernst Handel ERNSH Robert King
10835 1998/1/15 Alfreds Futterkiste ALFKI Nancy Davolio
10834 1998/1/15 Tradição Hipermercados TRADH Nancy Davolio
10833 1998/1/15 Ottilies Käseladen OTTIK Michael Suyama
10832 1998/1/14 La maison d'Asie LAMAI Andrew Fuller
10831 1998/1/14 Santé Gourmet SANTG Janet Leverling
10830 1998/1/13 Tradição Hipermercados TRADH Margaret Peacock
10829 1998/1/13 Island Trading ISLAT Anne Dodsworth
10828 1998/1/13 Rancho grande RANCH Anne Dodsworth
 First Prev ... 20 21 22 23 24 25 26 27 28 29 ... Next Last

路由定义:

     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();
        }
    }
}