个人写的分页方法

/**分页**/

#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">页面参数 &param1=value&param2=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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值