Asp.net文章內容分頁

來源:互聯網
上載者:User

標籤:c   style   class   blog   code   java   

#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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.