• 分页字符串帮助类


      1    /// <summary>
      2     /// 分页字符串帮助类
      3     /// </summary>
      4     public static class PageStrHelper
      5     {
      6         /// <summary>
      7         /// 获取分页字符串
      8         /// </summary>
      9         /// <param name="pageindex">当前页</param>
     10         /// <param name="pageMaxcount">最大条数</param>
     11         /// <param name="pageSize">每页条数</param>
     12         /// <returns></returns>
     13         public static string CreatePageStr(int pageindex, int pageMaxcount, int pageSize)
     14         {
     15             int pageMax = (int)Math.Ceiling(pageMaxcount * 1.0 / 10);//最大页数
     16 
     17             if (pageMax <= 1)
     18             {
     19                 return "";
     20             }
     21             StringBuilder sb = new StringBuilder();
     22             if (pageindex == 1)
     23             {
     24                 sb.AppendFormat("<ul class='pagination'><li><a class='disabled  page'  aria-label='Previous' page='{0}'><span aria-hidden='true'>&laquo;</span></a></li>", pageindex);
     25             }
     26             else
     27             {
     28                 sb.AppendFormat("<ul class='pagination'><li><a class='page'  aria-label='Previous' page='{0}'><span aria-hidden='true'>&laquo;</span></a></li>", pageindex - 1);
     29             }
     30 
     31             if (pageMax <= 10 && pageMax >= 2)
     32             {
     33 
     34                 for (int i = 1; i <= pageMax; i++)
     35                 {
     36                     if (i == pageindex)
     37                     {
     38                         sb.AppendFormat("<li><a class='actpage btn  page' page='{0}'>{0}</a></li>", i);
     39                     }
     40                     else
     41                     {
     42                         sb.AppendFormat("<li><a class='page' page='{0}'>{0}</a></li>", i);
     43                     }
     44                 }
     45             }
     46             if (pageMax > 10)
     47             {
     48                 int first = 1;
     49                 int end = pageMax;
     50                 if (pageindex >= 4 && pageindex <= pageMax - 4)
     51                 {
     52                     first = pageindex - 4;
     53                     end = pageindex + 4;
     54                 }
     55                 if (pageindex == 3)
     56                 {
     57                     first = 1;
     58                     end = 10;
     59                 }
     60                 if (pageindex == 2)
     61                 {
     62                     first = 1;
     63                     end = 10;
     64                 }
     65                 if (pageindex == 1)
     66                 {
     67                     first = 1;
     68                     end = 10;
     69                 }
     70                 if (pageindex == pageMax)
     71                 {
     72                     first = pageMax - 9;
     73                     end = pageMax;
     74                 }
     75                 if (pageindex == pageMax - 1)
     76                 {
     77                     first = pageMax - 9;
     78                     end = pageMax;
     79                 }
     80                 if (pageindex == pageMax - 2)
     81                 {
     82                     first = pageMax - 9;
     83                     end = pageMax;
     84                 }
     85                 if (pageindex == pageMax - 3)
     86                 {
     87                     first = pageMax - 9;
     88                     end = pageMax;
     89                 }
     90                 for (int i = first; i <= end; i++)
     91                 {
     92                     if (i == pageindex)
     93                     {
     94                         sb.AppendFormat("<li><a class='actpage btn page' page='{0}'>{0}</a></li>", i);
     95                     }
     96                     else
     97                     {
     98                         sb.AppendFormat("<li><a class='page' page='{0}'>{0}</a></li>", i);
     99                     }
    100 
    101                 }
    102             }
    103 
    104             if (pageindex == pageMax)
    105             {
    106                 sb.AppendFormat("<li><a class='disabled  page' aria-label='Next'  page='{0}'><span aria-hidden='true'>&raquo;</span></a></li></ul>", pageMax);
    107             }
    108             else
    109             {
    110                 sb.AppendFormat("<li><a class='page' aria-label='Next' page='{0}'><span aria-hidden='true'>&raquo;</span></a></li></ul>", pageindex + 1);
    111             }
    112 
    113             return sb.ToString();
    114         }
    115     }
    116 }
  • 相关阅读:
    修改 MyEclipse 中的 jsp 和 servlet 模板
    javaWeb 数据库连接池连接数据库
    发现一个类的方法不够用时,可以使用的3种方法可以增强
    使用 greenDao 框架 操作数据库
    Android之使用Volley框架在ListView中加载大量图片
    js日期选择控件
    mysql 乱码问题
    java 使用反射技术解耦
    javaWeb 使用jsp开发 html过滤标签
    javaWeb 使用jsp开发 foreach 标签
  • 原文地址:https://www.cnblogs.com/demoC/p/5121276.html
Copyright © 2020-2023  润新知