ASP.NET分页组装HTML代码
- // ASP.NET分页组装HTML代码
- //by bruce at 2017-05-15 17:31:41
- //
- public class Pager
- {
- public Pager(string _CateName, int _PageIndex, int _Total, int _PageSize)
- {
- this.PageIndex = _PageIndex;
- this.Total = _Total;
- this.PageSize = _PageSize;
- this.CateName = _CateName;
- }
- public int PageIndex { get; set; }
- public int Total { get; set; }
- public int PageSize { get; set; }
- public string CateName { get; set; }
- private int PageCount
- {
- get
- {
- var c = Total / PageSize;
- if (Total % PageSize > 0)
- {
- c += 1;
- }
- return c;
- }
- }
- private string GetUrl(int page)
- {
- return "";
- }
- public override string ToString()
- {
- if (0 == Total) return string.Empty;
- /* 计算分页零时变量 */
- //上一页
- int PrePage = PageIndex - 1;
- string PrePageString = PrePage > 0 ? ("<a class='prev' href='/" + CateName + "/" + PrePage + "'>上一页</a>") : "";
- //下一页
- int NextPage = PageIndex + 1;
- string NextPageString = (NextPage <= PageCount) ? ("<a class'next' href='/" + CateName + "/" + NextPage + "'>下一页</a>") : "";
- //第一页
- string FirstPageString = (PageIndex > 1) ? "<a class='first' href='/" + CateName + "/1'>首 页</a>" : "";
- //最后一页
- string EndPageString = (PageIndex < PageCount) ? "<a class='last' href='/" + CateName + "/" + PageCount + "'>末 页</a>" : "";
- //数字连接
- string link_page = "";
- int startPage = PageIndex - 2;
- int endPage = PageIndex + 2;
- if (endPage - startPage < 5)
- {
- if (PageIndex < 3)
- {
- endPage = endPage + 3 - PageIndex;
- }
- if (PageCount - PageIndex < 2)
- {
- startPage = startPage + PageCount - PageIndex - 2;
- }
- }
- for (int i = startPage; i <= endPage; i++)
- {
- if (i <= 0)
- {
- continue;
- }
- if (i > PageCount)
- {
- break;
- }
- var active = "class=''";
- if (PageIndex == i)
- {
- active = "class='active'";
- }
- link_page += "<a " + active + " href='/" + CateName + "/" + i + "'>" + i + "</a>";
- }
- return "<div class='pager'>" + FirstPageString + PrePageString + link_page + NextPageString + EndPageString + "</div>";
- }
- }
ASP.NET分页组装HTML代码
C#分页组装代码
============ 欢迎各位老板打赏~ ===========
与本文相关的文章
- · 使用jenkins远程布署.net项目
- · ASP.NET MVC分页 demo
- · c#/ASP.NET向百度站长平台主动推送URL
- · linux asp.net用httpWebRequest或WebClient访问https站点
- · 让Windows Server 2008 + IIS 7+ ASP.NET 支持10万并发请求
- · 支持高并发的IIS Web服务器常用设置
- · LINUX下部署ASP.NET:无需安装Mono的Jexus“独立版”
- · 最新asp.net/c#使用Memcached完整示例及注意事项
- · 讨论:关于ASP.NET用Timer定时执行问题
- · ASP.NET获取工程根目录
- · sql server使用ROW_NUMBER分页
- · ROW_NUMBER分页