zoukankan      html  css  js  c++  java
  • Asp.net文章内容分页

    #region Html内容分页处理函数
            /// <summary>
            /// Html内容分页处理函数 
            /// </summary>
            /// <param name="strBody">要分页的内容</param>
            /// <param name="strSplitString">分隔字符串</param>
            /// <param name="pageIndexName">页面索引参数名</param>
            /// <param name="patter">链接匹配模式</param>
            /// <param name="isAppendHeadEnd">是否追加第一页和最后一页</param>
            /// <returns></returns>
            public static string CreateContentPager(ref string strBody,
                                        string strSplitString,
                                        string pageIndexName,
                                        string patter,
                                        bool isAppendHeadEnd)
            {
                string[] strBodyArray = strBody.Split(new string[] { strSplitString }, StringSplitOptions.None);
                //分页内容
                StringBuilder strHtmlPager = new StringBuilder();
                int currentPageIndex = 1; //当前页页码
                int pageCount = strBodyArray.Length;//总页数
                if (!string.IsNullOrEmpty(HttpContext.Current.Request[pageIndexName]))
                {
                    currentPageIndex = CommonFunction.getInteger(HttpContext.Current.Request[pageIndexName]);
                }
                //无需分页
                if (pageCount == 1)
                {
                    return null;
                }
                //开始分页处理
                if (isAppendHeadEnd)
                {
                    if (currentPageIndex == 1)
                    {
                        strHtmlPager.AppendLine();
                        strHtmlPager.Append("<b>[第一页]</b>");
                    }
                    else
                    {
                        strHtmlPager.AppendLine();
                        strHtmlPager.Append(patter.Replace("{0}", 1.ToString()).Replace("{1}", "第一页"));
                    }
                }
                //页头
                if (currentPageIndex > 1)
                {
                    //显示上一页
                    strHtmlPager.AppendLine();
                    strHtmlPager.Append(patter.Replace("{0}", (currentPageIndex - 1).ToString()).Replace("{1}", "上一页"));
                }
                else
                {
                    if (currentPageIndex == 1)
                    {
                        strHtmlPager.AppendLine();
                        strHtmlPager.Append("<b>[上一页]</b>");
                    }
                }
                //开始分页
                for (int i = 1; i <= pageCount; i++)
                {
                    //如果 当前页索引=页码的话,执行操作标示当前页码
                    if (i == currentPageIndex)
                    {
                        strHtmlPager.AppendLine();
                        strHtmlPager.AppendFormat("<b>[{0}]</b>", i);
                    }
                    else
                    {
                        strHtmlPager.AppendLine();
                        strHtmlPager.AppendFormat(patter.Replace("{0}", i.ToString()).Replace("{1}", i.ToString()));
                    }
                }
                //页尾
                if (currentPageIndex + 1 > pageCount)
                {
                    strHtmlPager.AppendLine();
                    strHtmlPager.Append("<b>[下一页]</b>");
                }
                else
                {
                    strHtmlPager.AppendLine();
                    strHtmlPager.Append(patter.Replace("{0}", (currentPageIndex + 1).ToString()).Replace("{1}", "下一页"));
                }
                if (isAppendHeadEnd)
                {
                    if (currentPageIndex == pageCount)
                    {
                        strHtmlPager.AppendLine();
                        strHtmlPager.Append("<b>[已经是最后一页]</b>");
                    }
                    else
                    {
                        strHtmlPager.AppendLine();
                        strHtmlPager.Append(patter.Replace("{0}", pageCount.ToString()).Replace("{1}", "最后一页"));
                    }
                }
                strBody = strBodyArray[currentPageIndex - 1];
                return strHtmlPager.ToString();
            }
            #endregion
  • 相关阅读:
    世界上最快的排序算法——Timsort
    十二种排序包你满意(冒泡、插入、归并、快速排序等包含希尔和计数排序)
    二叉树遍历方法大全(包含莫里斯遍历)
    Nginx知多少系列之(一)前言
    .NET Core项目部署到Linux(Centos7)(一)前言
    Nginx知多少系列之(十四)Linux下.NET Core项目Nginx+Keepalived高可用(主从模式)
    Nginx知多少系列之(七)负载均衡策略
    Nginx知多少系列之(六)Linux下.NET Core项目负载均衡
    Nginx知多少系列之(五)Linux下托管.NET Core项目
    Nginx知多少系列之(四)工作原理
  • 原文地址:https://www.cnblogs.com/cpine/p/3777349.html
Copyright © 2011-2022 走看看