个人写的分页方法
/**分頁**/
#PageConDiv{padding:10px; margin:0px auto; text-align:right; }
#PageConDiv span a,#PageConDiv span span{ display:inline-block;text-align:center;height:20px; padding:0 8px;vertical-align:middle;line-height:20px;text-decoration:none; /*color:#8195b6;background:#e9f5e7;*/font-size:12px; margin-right:5px; color:#000; border:solid 1px #ddd; background:#fafafa;}
#PageConDiv span .SelPageA{ color:#5f7a5b; border:solid 1px #5f7a5b; background:#EBEEF6; font-weight:bold;}
#PageConDiv span .PrvA{}
#PageConDiv span .NextA{}
#PageConDiv span .GotoSpan{ padding:0px; margin-right:0px; border-right:none;}
#PageConDiv span #Gotobox{width:25px;height:14px;border:solid 1px #ccc; margin:0px;padding:0px; margin:2px; margin-bottom:0px;}
#PageConDiv span #GotoBtn{}
/// <summary>/// 分頁頁碼生成/// </summary>/// <param name="CurrPage">當前頁碼</param>/// <param name="PageCount">總頁數</param>/// <param name="Params">頁面參數 ¶m1=value¶m2=value樣式</param>/// <returns></returns>protected string PagerControl(int CurrPage, int PageCount,string Params){System.Text.StringBuilder PageStr = new System.Text.StringBuilder(); //分頁生成字符CurrPage = CurrPage <= PageCount && CurrPage > 0 ? CurrPage : CurrPage > 0 ? PageCount : 1; //處理錯誤輸入PageStr.Append("<span>");if (PageCount > 1){string DirectUrl = Request.Url.LocalPath.ToString();//頁面地址int BeginIndex, EndIndex;// 首頁|上一頁if (CurrPage > 1){PageStr.Append("<a href=\"" + DirectUrl + "?page=1" + Params + " \">首頁</a>");PageStr.Append("<a class='PrvA' href=\"" + DirectUrl + "?page=" + (CurrPage - 1) + Params + " \">上一頁</a>");}#region 初始頁碼計算if (PageCount > 10){if (CurrPage > 6){if (!(PageCount < (CurrPage + 4))){BeginIndex = CurrPage - 5;EndIndex = CurrPage + 4;}else{BeginIndex = PageCount - 9;EndIndex = PageCount;}}else{BeginIndex = 1;EndIndex = 10;}}else{BeginIndex = 1;EndIndex = PageCount;}#endregion#region 頁碼生成for (int i = BeginIndex; i < EndIndex + 1; i++){PageStr.Append("<a " + (i != CurrPage ? "" : "class=\"SelPageA\"") + " href=\"" + DirectUrl + "?page=" + i + Params + "\">" + i + "</a>");}if (PageCount > 10 && PageCount - CurrPage > 4){PageStr.Append("<a href=\"" + DirectUrl + "?page=" + PageCount + Params + "\">..." + PageCount + "</a>");}#endregion// 下一頁|尾頁if (CurrPage < PageCount){PageStr.Append("<a class='NextA' href=\"" + DirectUrl + "?page=" + (CurrPage + 1) + Params + " \">下一頁</a>");}// 跳轉頁if (PageCount > 5){PageStr.Append("<span class=\"GotoSpan\"><input type='text' id='Gotobox' /></span>");PageStr.Append("<a id=\"GotoBtn\" href=\"" + DirectUrl + "?page=" + PageCount + Params + " \">跳</a>");}}PageStr.Append("</span>");return PageStr.ToString();}
轉載于:https://www.cnblogs.com/xiaohei609/archive/2012/07/10/2583945.html
總結
- 上一篇: 如何在工作中自学UI设计
- 下一篇: MXBean