<%
int totalCount = Convert.ToInt32(ViewData["totalCount"]);
int pageNum = Convert.ToInt32((ViewData["pageNum"] == null ? '1' : ViewData["pageNum"]));
int totalPages = totalCount / 20 + (totalCount % 20 > 0 ? 1 : 0);
%>
<div class="page pageBottom">
<label class="right blackColor">
共<%= totalCount %>条记录 每页20条 共<%= totalPages %>页 页次<%= pageNum %>/<%= totalPages %> 分页:
</label>
<div style="float:left">
<%
if (pageNum > 1)
{
%>
<a href="javascript:searchDiamondsByPage(<%= pageNum-1 %>);">
<img src="/Content/images/Paging/btn-pre.gif" alt=""/>
</a>
<%
}
else {
%>
<a href="javascript:searchDiamondsByPage(1);">
<img src="/Content/images/Paging/btn-pre.gif" alt=""/>
</a>
<%
}
%>
<% if (pageNum < 6)
{
int m = 1;
int p = pageNum;
if (totalPages >= 3)
{
for (; m <=(p+2>=totalPages-1?totalPages-2:p+2); m++)
{ %>
<a href="javascript:searchDiamondsByPage(<%= m %>);" class='<%= (m == pageNum)? "priceColor bold" : "defaultColor" %>'><%= m%></a>
<% }
%>
<a>…</a>
<%
int n = totalPages - 1;
for (; n <= totalPages; n++)
{ %>
<a href="javascript:searchDiamondsByPage(<%= n %>);" class='<%= (n == pageNum)? "priceColor bold" : "defaultColor" %>'><%= n %></a>
<% }
}
if (totalPages < 3)
{
int t = 1;
int y = 2;
for (; t <= (y >= totalPages ? totalPages : t); t++)
{ %>
<a href="javascript:searchDiamondsByPage(<%= t %>);" class='<%= (t == pageNum)? "priceColor bold" : "defaultColor" %>'><%= t%></a>
<% }
}
} %>
<% if (pageNum >= 6 && pageNum < totalPages - 3)
{
int m = 1;
for (; m <= 2; m++)
{ %>
<a href="javascript:searchDiamondsByPage(<%= m %>);" class='<%= (m == pageNum)? "priceColor bold" : "defaultColor" %>'><%= m %></a>
<% } %>
<a>...</a>
<% int n = pageNum-2;
int k = n + 5;
for (; n < k; n++)
{ %>
<a href="javascript:searchDiamondsByPage(<%= n %>);" class='<%= (n == pageNum)? "priceColor bold" : "defaultColor" %>'><%= n %></a>
<% } %>
<a>...</a>
<%
int p = totalPages - 1;
for (; p <= totalPages; p++)
{ %>
<a href="javascript:searchDiamondsByPage(<%= p %>);" class='<%= (p == pageNum)? "priceColor bold" : "defaultColor" %>'><%= p %></a>
<% }
} %>
<% if (pageNum >= totalPages - 3 && totalPages>5 && pageNum>=6)
{
int m = 1;
for (; m <= 2; m++)
{ %>
<a href="javascript:searchDiamondsByPage(<%= m %>);" class='<%= (m == pageNum)? "priceColor bold" : "defaultColor" %>'><%= m%></a>
<% } %>
<a>...</a>
<% int n = pageNum-2;
for (; n <= totalPages; n++)
{ %>
<a href="javascript:searchDiamondsByPage(<%= n %>);" class='<%= (n == pageNum)? "priceColor bold" : "defaultColor" %>'><%= n%></a>
<% }
} %>
<%
if (pageNum < totalPages)
{
%>
<a href="javascript:searchDiamondsByPage(<%=pageNum+1 %>);">
<img src="/Content/images/Paging/btn-next.gif" alt=""/>
</a>
<%
}
else {
%>
<a href="javascript:void();">
<img src="/Content/images/Paging/btn-next.gif" alt=""/>
</a>
<%
}
%>
</div>
</div>
css
/*Paging*/
.page{ line-height:34px; height:34px;}
.pageBottom{ border-bottom:1px solid #ddd;}
.right{ float:right;}
.blackColor{ color:#000;}
.defaultColor{ color:#666;}
.bold{ font-weight:bold;}
.priceColor{ color:#ef2265;}