aspx页面上的分页逻辑

<%  
    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;}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值