• asp.net数据分页方法


    /// <summary>
            /// 数据分页方法
            /// </summary>
            /// <param name="PageIndex">当前页</param>
            /// <param name="PageSize">每页显示数量</param>
            /// <param name="PageCount">总数据</param>
            /// <param name="Url">链接,如:list.aspx?id=1234</param>
            /// <returns></returns>
            public static string GetPage(int PageIndex, int PageSize, int RecordCount, string Url)
            {
                StringBuilder sb = new StringBuilder();
                try
                {
                    //计算总页数
                    int PageCount = RecordCount % PageSize == 0 ? RecordCount / PageSize : RecordCount / PageSize + 1;
                    if (PageIndex < 1)
                    {
                        PageIndex = 1;
                    }
                    if (PageIndex > PageCount)
                    {
                        PageIndex = PageCount;
                    }
                    string StarPage = "";//首页
                    string EndPage = "";//尾页
                    string PrePage = "";//上一页
                    string NextPage = "";//下一页
                    //首页和上一页的链接
                    if (PageIndex <= 1 || PageCount <= 1)
                    {
                        StarPage = "";
                        PrePage = "";
                    }
                    else
                    {
                        StarPage = "";
                        PrePage = "<li class="previous"><a href="" + Url + "&page=" + (PageIndex - 1) + "">上一页</a></li>";
                    }
                    //末页和下一页的链接
                    if (PageIndex == PageCount || PageCount <= 1)
                    {
                        EndPage = "";
                        NextPage = "";
                    }
                    else
                    {
                        EndPage = "";
                        NextPage = "<li class="next"><a href="" + Url + "&page=" + (PageIndex + 1) + "">下一页</a></li>";
                    }
                    //页码输出
                    int PagerStart = 1;//第一个页码
                    if (PageCount >= 5)
                    {
                        PagerStart = PageIndex % 5 == 0 ? PageIndex - 2 : PageIndex - PageIndex % 5;
                    }
                    if (PagerStart < 1)
                    {
                        PagerStart = 1;
                    }
                    string NumBtn = "";
                    for (int i = PagerStart; i < PagerStart + 5 && i <= PageCount; i++)
                    {
                        if (i == PageIndex)
                        {
                            NumBtn += "<li class="current"><a>" + i + "</a>";
                        }
                        else
                        {
                            NumBtn += "<li><a href="" + Url + "&page=" + i + "">" + i + "</a></li>";
                        }
                    }
                    sb.Append(StarPage + PrePage + NumBtn + NextPage + EndPage);
                }
                catch
                {
                    sb.Append("");
                }
                return sb.ToString();
            }

    具体样式可以去www.weixh.net参考一下

  • 相关阅读:
    函数进阶-生成器
    函数进阶-列表生成式
    闭包
    命名空间
    内置方法
    函数
    squid清除缓存
    subprocess实现管道
    Python统计脚本行数(fileinput)
    fabric note
  • 原文地址:https://www.cnblogs.com/sanjuantianshu/p/3924591.html
Copyright © 2020-2023  润新知