標籤: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