Fork me on GitHub

UrlPager 示例 - Url逆向分页

本示例演示如何使用UrlPager分页控件进行逆向分页,逆向分页即Url中显示的页索引与实际页索引逆转。
Order IDOrder DateCompany NameCustomer IDEmployee Name
10827 1998/1/12 Bon app' BONAP Nancy Davolio
10826 1998/1/12 Blondesddsl père et fils BLONP Michael Suyama
10825 1998/1/9 Drachenblut Delikatessen DRACD Nancy Davolio
10824 1998/1/9 Folk och fä HB FOLKO Laura Callahan
10823 1998/1/9 LILA-Supermercado LILAS Steven Buchanan
10822 1998/1/8 Trail's Head Gourmet Provisioners TRAIH Michael Suyama
10821 1998/1/8 Split Rail Beer & Ale SPLIR Nancy Davolio
10820 1998/1/7 Rattlesnake Canyon Grocery RATTC Janet Leverling
10819 1998/1/7 Cactus Comidas para llevar CACTU Andrew Fuller
10818 1998/1/7 Magazzini Alimentari Riuniti MAGAA Robert King
 First Prev ... 21 22 23 24 25 26 27 28 29 30 ... Next Last

路由定义:

routes.MapPageRoute("UrlPager_ReversePageIndex",
                "urlpager/demos/{controller}/{action}/{pageIndex}",
                "~/UrlPager/Demos/ReversePageIndex.aspx", false, new RouteValueDictionary { { "controller", "ReversePageIndex" }, { "action", "List" }, { "pageIndex", null } }, new RouteValueDictionary { { "controller", "ReversePageIndex" }, { "action", "List" } });
   

ReversePageIndex.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_ReversePageIndex" PagerItemTemplate="&nbsp;{0}"
                       ReversePageIndex="true" OnPageChanged="PageChanged"></webdiyer:UrlPager> 
 

ReversePageIndex.aspx.cs:

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace Webdiyer.UrlPagerDemo
{
    public partial class ReversePageIndex : 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();
        }
    }
}