Apply styles to MvcPager
This sample demonstrate how to apply css styles to MvcPager, code:
<%=Html.Pager(Model,new PagerOptions{PageIndexParameterName="id",CurrentPagerItemWrapperFormatString = "<span class=\"cpb\">{0}</span>",NumericPagerItemWrapperFormatString = "<span class=\"item\">{0}</span>",CssClass = "pages",SeparatorHtml=""}) %>
<%=Html.Pager(Model,new PagerOptions{PageIndexParameterName="id",CurrentPagerItemWrapperFormatString = "<span class=\"cpb\">{0}</span>",NumericPagerItemWrapperFormatString = "<span class=\"item\">{0}</span>",CssClass = "pages",SeparatorHtml=""}) %>
| Order ID | Order Date | Customer ID | Ship Address |
|---|---|---|---|
| 10920 | 3/3/1998 12:00:00 AM | AROUT | Brook Farm Stratford St. Mary |
| 10921 | 3/3/1998 12:00:00 AM | VAFFE | Smagsloget 45 |
| 10922 | 3/3/1998 12:00:00 AM | HANAR | Rua do Paço, 67 |
| 10923 | 3/3/1998 12:00:00 AM | LAMAI | 1 rue Alsace-Lorraine |
| 10924 | 3/4/1998 12:00:00 AM | BERGS | Berguvsvägen 8 |
| 10925 | 3/4/1998 12:00:00 AM | HANAR | Rua do Paço, 67 |
| 10926 | 3/4/1998 12:00:00 AM | ANATR | Avda. de la Constitución 2222 |
| 10927 | 3/5/1998 12:00:00 AM | LACOR | 67, avenue de l'Europe |
| 10928 | 3/5/1998 12:00:00 AM | GALED | Rambla de Cataluña, 23 |
| 10929 | 3/5/1998 12:00:00 AM | FRANK | Berliner Platz 43 |
| 10930 | 3/6/1998 12:00:00 AM | SUPRD | Boulevard Tirou, 255 |
| 10931 | 3/6/1998 12:00:00 AM | RICSU | Starenweg 5 |
| 10932 | 3/6/1998 12:00:00 AM | BONAP | 12, rue des Bouchers |
| 10933 | 3/6/1998 12:00:00 AM | ISLAT | Garden House Crowther Way |
| 10934 | 3/9/1998 12:00:00 AM | LEHMS | Magazinweg 7 |
| 10935 | 3/9/1998 12:00:00 AM | WELLI | Rua do Mercado, 12 |
| 10936 | 3/9/1998 12:00:00 AM | GREAL | 2732 Baker Blvd. |
| 10937 | 3/10/1998 12:00:00 AM | CACTU | Cerrito 333 |
| 10938 | 3/10/1998 12:00:00 AM | QUICK | Taucherstraße 10 |
| 10939 | 3/10/1998 12:00:00 AM | MAGAA | Via Ludovico il Moro 22 |
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<PagedList<Order>>" %>
<%@ Import Namespace="Webdiyer.Mvc2Demo.Models"%>
<%@ Import Namespace="Webdiyer.WebControls.Mvc"%>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Apply styles to MvcPager
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Apply styles to MvcPager</h2>
<div>This sample demonstrate how to apply css styles to MvcPager, code:<br />
<%=Html.Pager(Model,new PagerOptions{PageIndexParameterName="id",
CurrentPagerItemWrapperFormatString = "<span class=\"cpb\">{0}</span>",
NumericPagerItemWrapperFormatString = "<span class=\"item\">{0}</span>",
CssClass = "pages",SeparatorHtml=""}) %>
</div><br />
<table width="98%">
<tr><th>Order ID</th><th>Order Date</th><th>Customer ID</th><th>Ship Address</th></tr>
<%foreach(Order od in Model)
{
%>
<tr><td><%=od.OrderID %></td><td><%=od.OrderDate.ToString() %></td>
<td><%=od.CustomerID %></td><td><%=od.ShipAddress %></td></tr>
<%
} %>
</table>
<%=Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id",
CurrentPagerItemWrapperFormatString = "<span class=\"cpb\">{0}</span>",
NumericPagerItemWrapperFormatString = "<span class=\"item\">{0}</span>",
CssClass = "pages", SeparatorHtml = "" })%>
</asp:Content>
public ActionResult ApplyStyles(int? id)
{
using (var db = new MvcPagerDemoDataContext())
{
PagedList<Order> orders = db.Orders.ToPagedList(id ?? 1, 20);
return View(orders);
}
}
/*pager style*/
.pages { color:red;font-weight:bold; font-size:11px;}
.pages .item{padding: 1px 6px;font-size: 13px;} /*numeric pager items*/
.pages .cpb {color:red;padding: 1px 6px;font-size: 13px;} /*current pager item*/
.pages a { text-decoration:none;padding: 0 5px; border: 1px solid #ddd;
margin:0 2px; color:#000;font-weight:normal;}
.pages a:hover { background-color: #E61636; color:#fff;
border:1px solid #E61636; text-decoration:none;font-weight:normal;}