A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© sunrise2 高级黑马   /  2014-8-11 18:08  /  983 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. #region Html内容分页处理函数
  2.         /// <summary>
  3.         /// Html内容分页处理函数
  4.         /// </summary>
  5.         /// <param name="strBody">要分页的内容</param>
  6.         /// <param name="strSplitString">分隔字符串</param>
  7.         /// <param name="pageIndexName">页面索引参数名</param>
  8.         /// <param name="patter">链接匹配模式</param>
  9.         /// <param name="isAppendHeadEnd">是否追加第一页和最后一页</param>
  10.         /// <returns></returns>
  11.         public static string CreateContentPager(ref string strBody,
  12.                                     string strSplitString,
  13.                                     string pageIndexName,
  14.                                     string patter,
  15.                                     bool isAppendHeadEnd)
  16.         {
  17.             string[] strBodyArray = strBody.Split(new string[] { strSplitString }, StringSplitOptions.None);
  18.             //分页内容
  19.             StringBuilder strHtmlPager = new StringBuilder();
  20.             int currentPageIndex = 1; //当前页页码
  21.             int pageCount = strBodyArray.Length;//总页数
  22.             if (!string.IsNullOrEmpty(HttpContext.Current.Request[pageIndexName]))
  23.             {
  24.                 currentPageIndex = CommonFunction.getInteger(HttpContext.Current.Request[pageIndexName]);
  25.             }
  26.             //无需分页
  27.             if (pageCount == 1)
  28.             {
  29.                 return null;
  30.             }
  31.             //开始分页处理
  32.             if (isAppendHeadEnd)
  33.             {
  34.                 if (currentPageIndex == 1)
  35.                 {
  36.                     strHtmlPager.AppendLine();
  37.                     strHtmlPager.Append("<b>[第一页]</b>");
  38.                 }
  39.                 else
  40.                 {
  41.                     strHtmlPager.AppendLine();
  42.                     strHtmlPager.Append(patter.Replace("{0}", 1.ToString()).Replace("{1}", "第一页"));
  43.                 }
  44.             }
  45.             //页头
  46.             if (currentPageIndex > 1)
  47.             {
  48.                 //显示上一页
  49.                 strHtmlPager.AppendLine();
  50.                 strHtmlPager.Append(patter.Replace("{0}", (currentPageIndex - 1).ToString()).Replace("{1}", "上一页"));
  51.             }
  52.             else
  53.             {
  54.                 if (currentPageIndex == 1)
  55.                 {
  56.                     strHtmlPager.AppendLine();
  57.                     strHtmlPager.Append("<b>[上一页]</b>");
  58.                 }
  59.             }
  60.             //开始分页
  61.             for (int i = 1; i <= pageCount; i++)
  62.             {
  63.                 //如果 当前页索引=页码的话,执行操作标示当前页码
  64.                 if (i == currentPageIndex)
  65.                 {
  66.                     strHtmlPager.AppendLine();
  67.                     strHtmlPager.AppendFormat("<b>[{0}]</b>", i);
  68.                 }
  69.                 else
  70.                 {
  71.                     strHtmlPager.AppendLine();
  72.                     strHtmlPager.AppendFormat(patter.Replace("{0}", i.ToString()).Replace("{1}", i.ToString()));
  73.                 }
  74.             }
  75.             //页尾
  76.             if (currentPageIndex + 1 > pageCount)
  77.             {
  78.                 strHtmlPager.AppendLine();
  79.                 strHtmlPager.Append("<b>[下一页]</b>");
  80.             }
  81.             else
  82.             {
  83.                 strHtmlPager.AppendLine();
  84.                 strHtmlPager.Append(patter.Replace("{0}", (currentPageIndex + 1).ToString()).Replace("{1}", "下一页"));
  85.             }
  86.             if (isAppendHeadEnd)
  87.             {
  88.                 if (currentPageIndex == pageCount)
  89.                 {
  90.                     strHtmlPager.AppendLine();
  91.                     strHtmlPager.Append("<b>[已经是最后一页]</b>");
  92.                 }
  93.                 else
  94.                 {
  95.                     strHtmlPager.AppendLine();
  96.                     strHtmlPager.Append(patter.Replace("{0}", pageCount.ToString()).Replace("{1}", "最后一页"));
  97.                 }
  98.             }
  99.             strBody = strBodyArray[currentPageIndex - 1];
  100.             return strHtmlPager.ToString();
  101.         }
  102.         #endregion
复制代码


1 个回复

倒序浏览
学习一下
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马