asp.net 分頁

來源:互聯網
上載者:User

標籤:style   blog   io   ar   color   os   sp   for   on   

/// <summary> /// 分頁內容 /// </summary> /// <param name="size">頁面大小</param> /// <param name="count">頁面數量</param> /// <param name="currendIndex">當前頁</param> /// <param name="pattern">url模式:demo.aspx?page={0}</param> /// <param name="target">視窗模式</param> /// <returns></returns> public static string get_pagenation(int size,                                     int count,                                     int currendIndex,                                     string pattern,                                     string target) {     //1>開啟視窗目標     target = string.IsNullOrEmpty(target) ? "_top" : target;     //2>總頁數     int pageCount = count / size;     pageCount = pageCount * size == count ? pageCount : pageCount + 1;     //3>分頁內容     StringBuilder strHtml = new StringBuilder();     strHtml.Append("<span class=‘pagenation‘>");     #region 首部處理     if (currendIndex > 1)     {         strHtml.AppendFormat("<a href=‘1‘ target=‘{0}‘>[首頁]</a>", target);         strHtml.AppendFormat("<a href=‘{0}‘ target=‘{1}‘>[上一頁]</a>", string.Format(pattern, currendIndex - 1), target);     }     else    {         strHtml.Append("<span class=‘disabled‘>[首頁]</span>  <span class=‘disabled‘>[上一頁]</span>");     }     #endregion     #region 中間部分     int i = 1;     int right = (currendIndex + 4) > pageCount ? pageCount : currendIndex + 4;     if (currendIndex > 6)     {         i = currendIndex - 5;     }     else    {         right = pageCount >= 10 ? 10 : pageCount;     }     for (; i <= right; i++)     {         if (i == currendIndex)         {             strHtml.AppendFormat("<font class=‘current‘>{0}</font>", i);             strHtml.AppendLine();             continue;         }         strHtml.AppendFormat("<a href=‘{0}‘ target=‘{1}‘>[{2}]</a>", string.Format(pattern, i), target, i);         strHtml.AppendLine();     }     #endregion     #region 尾部處理     if (currendIndex == pageCount)     {         strHtml.Append("<span class=‘disabled‘>[下一頁]</span><span class=‘disabled‘>[末頁]</span>");         strHtml.AppendFormat("總共({0})頁", pageCount);     }     else    {         strHtml.AppendFormat("<a href=‘{0}‘ target=‘{1}‘>[下一頁]</a>", string.Format(pattern, currendIndex + 1), target);         strHtml.AppendFormat("<a href=‘{0}‘ target=‘{1}‘>[末頁]</a>", string.Format(pattern, pageCount), target);         strHtml.AppendFormat("  <label>總共({0})頁</label>", pageCount);     }     #endregion     strHtml.Append("</span>");     return strHtml.ToString(); } 

 

asp.net 分頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.