Fork me on GitHub

UrlPager 示例 - 设置RouteValues

本示例演示如何通过RouteValues为UrlPager分页控件设置参数。
Order IDOrder DateCompany NameCustomer IDEmployee Name
10867 1998/2/3 Lonesome Pine Restaurant LONEP Michael Suyama
10866 1998/2/3 Berglunds snabbköp BERGS Steven Buchanan
10865 1998/2/2 QUICK-Stop QUICK Andrew Fuller
10864 1998/2/2 Around the Horn AROUT Margaret Peacock
10863 1998/2/2 HILARION-Abastos HILAA Margaret Peacock
10862 1998/1/30 Lehmanns Marktstand LEHMS Laura Callahan
10861 1998/1/30 White Clover Markets WHITC Margaret Peacock
10860 1998/1/29 France restauration FRANR Janet Leverling
10859 1998/1/29 Frankenversand FRANK Nancy Davolio
10858 1998/1/29 La corne d'abondance LACOR Andrew Fuller
 First Prev ... 17 18 19 20 21 22 23 24 25 26 ... Next Last

路由定义:

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

RouteValues.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_RouteValues" CssClass="pull-right" PageIndexParameterName="id"
                        RouteValues="<%$RouteValues:controller=RouteValues,action=ShowPage,city=yanan,author=webdiyer%>" OnPageChanged="PageChanged" PagerItemTemplate="&nbsp;{0}"></webdiyer:UrlPager> 
 

Default.aspx.cs:

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