• PageBarHelper分页显示类


    一共有两个分页类,都可以使用(单独使用)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace Common
    {
    public class PageBarHelper
    {
    /// <summary>
    /// 计算数字页码条
    /// </summary>
    /// <param name="pageIndex">当前页码</param>
    /// <param name="pageCount">总页数</param>
    /// <returns></returns>
    public static string GetPageBar(int pageIndex,int pageCount)
    {
    if (pageCount == 1)
    {
    return string.Empty;
    }
    //要求页面上要显示10个数字页码。
    int start = pageIndex - 5;//计算起始位置
    if (start < 1)
    {
    start = 1;
    }
    int end = start + 9;//计算终止位置.
    if (end > pageCount)
    {
    end = pageCount;
    start = end - 9<1?1:end-9;
    }
    StringBuilder sb = new StringBuilder();
    if (pageIndex > 1)
    {
    sb.Append(string.Format("<a href='?pageIndex={0}' class='pageBarIndex'>上一页</a>", pageIndex - 1));
    }
    for (int i = start; i <= end; i++)
    {
    if (i == pageIndex)
    {
    sb.Append(i);
    }
    else
    {
    sb.Append(string.Format("<a href='?pageIndex={0}' class='pageBarIndex'>{0}</a>",i));
    }
    }
    if (pageIndex < pageCount)
    {
    sb.Append(string.Format("<a href='?pageIndex={0}' class='pageBarIndex'>下一页</a>", pageIndex + 1));
    }

    return sb.ToString();
    }
    }
    }

    ---------------------------------------------------------------------------分划线-------------------------------------------------------------------------------

    using System;
    using System.Text;

    namespace WebDemo.Common
    {
    public class LaomaPager
    {
    /// <summary>
    ///
    /// </summary>
    /// <param name="pageSize">一页多少条</param>
    /// <param name="currentPage">当前页</param>
    /// <param name="totalCount">总条数</param>
    /// <returns></returns>
    public static string ShowPageNavigate(int pageSize, int currentPage, int totalCount)
    {
    string redirectTo = "";
    pageSize = pageSize == 0 ? 3 : pageSize;
    var totalPages = Math.Max((totalCount + pageSize - 1) / pageSize, 1); //总页数
    var output = new StringBuilder();
    if (totalPages > 1)
    {
    if (currentPage != 1)
    {//处理首页连接
    output.AppendFormat("<a class='pageLink' href='{0}?pageIndex=1&pageSize={1}'>首页</a> ", redirectTo, pageSize);
    }
    if (currentPage > 1)
    {//处理上一页的连接
    output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>上一页</a> ", redirectTo, currentPage - 1, pageSize);
    }
    else
    {
    // output.Append("<span class='pageLink'>上一页</span>");
    }

    output.Append(" ");
    int currint = 5;
    for (int i = 0; i <= 10; i++)
    {//一共最多显示10个页码,前面5个,后面5个
    if ((currentPage + i - currint) >= 1 && (currentPage + i - currint) <= totalPages)
    {
    if (currint == i)
    {//当前页处理
    //output.Append(string.Format("[{0}]", currentPage));
    output.AppendFormat("<a class='cpb' href='{0}?pageIndex={1}&pageSize={2}'>{3}</a> ", redirectTo, currentPage, pageSize, currentPage);
    }
    else
    {//一般页处理
    output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>{3}</a> ", redirectTo, currentPage + i - currint, pageSize, currentPage + i - currint);
    }
    }
    output.Append(" ");
    }
    if (currentPage < totalPages)
    {//处理下一页的链接
    output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>下一页</a> ", redirectTo, currentPage + 1, pageSize);
    }
    else
    {
    //output.Append("<span class='pageLink'>下一页</span>");
    }
    output.Append(" ");
    if (currentPage != totalPages)
    {
    output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>末页</a> ", redirectTo, totalPages, pageSize);
    }
    output.Append(" ");
    }
    output.AppendFormat("第{0}页 / 共{1}页", currentPage, totalPages);//这个统计加不加都行
    return output.ToString();
    }
    }
    }

  • 相关阅读:
    计算机的启动过程
    project
    ERROR
    告别,是另一种体验
    Kean博客2006年9月-2007年8月链接
    AutoCAD .NET开发大师Kean有价值的博客 2006年8月 .NET内容整理
    VS2010 VS2012拖拽NumericUpDown控件直接卡死的解决办法
    2006-7有价值的Kean博客——Calling ObjectARX functions from a .NET Application(PInvoke)
    使用NetApi渲染Cad模型
    Kean专题:拖动一个属性块(JIG拖拽)
  • 原文地址:https://www.cnblogs.com/jiangyunfeng/p/11266439.html
Copyright © 2020-2023  润新知