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 |
|---|---|---|---|
| 10760 | 12/1/1997 12:00:00 AM | MAISD | Rue Joseph-Bens 532 |
| 10761 | 12/2/1997 12:00:00 AM | RATTC | 2817 Milton Dr. |
| 10762 | 12/2/1997 12:00:00 AM | FOLKO | Åkergatan 24 |
| 10763 | 12/3/1997 12:00:00 AM | FOLIG | 184, chaussée de Tournai |
| 10764 | 12/3/1997 12:00:00 AM | ERNSH | Kirchgasse 6 |
| 10765 | 12/4/1997 12:00:00 AM | QUICK | Taucherstraße 10 |
| 10766 | 12/5/1997 12:00:00 AM | OTTIK | Mehrheimerstr. 369 |
| 10767 | 12/5/1997 12:00:00 AM | SUPRD | Boulevard Tirou, 255 |
| 10768 | 12/8/1997 12:00:00 AM | AROUT | Brook Farm Stratford St. Mary |
| 10769 | 12/8/1997 12:00:00 AM | VAFFE | Smagsloget 45 |
| 10770 | 12/9/1997 12:00:00 AM | HANAR | Rua do Paço, 67 |
| 10771 | 12/10/1997 12:00:00 AM | ERNSH | Kirchgasse 6 |
| 10772 | 12/10/1997 12:00:00 AM | LEHMS | Magazinweg 7 |
| 10773 | 12/11/1997 12:00:00 AM | ERNSH | Kirchgasse 6 |
| 10774 | 12/11/1997 12:00:00 AM | FOLKO | Åkergatan 24 |
| 10775 | 12/12/1997 12:00:00 AM | THECR | 55 Grizzly Peak Rd. |
| 10776 | 12/15/1997 12:00:00 AM | ERNSH | Kirchgasse 6 |
| 10777 | 12/15/1997 12:00:00 AM | GOURL | Av. Brasil, 442 |
| 10778 | 12/16/1997 12:00:00 AM | BERGS | Berguvsvägen 8 |
| 10779 | 12/16/1997 12:00:00 AM | MORGK | Heerstr. 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;}