cPage分页源码,分享给大家,可作参考

cPage是asp.net分页控件,也可以叫做分页组件,更确切的应该叫做分页模块,也或者叫做分页通用代码。

cPage,版本3.2,源码如下:

 

 

using System;

 

namespace cPage

{

    /// <summary>

    /// 分页方法

    /// </summary>

    public class mPage

    {

        /// <summary>

        /// 分页处理

        /// </summary>

        /// <param name="recordCount">记录总数</param>

        /// <param name="pageSize">每页记录数</param>

        /// <param name="pageNum">中间页码数</param>

        /// <param name="pageIndex">当前页码</param>

        /// <param name="beginIndex">返回的首记录标识</param>

        /// <param name="endIndex">返回的尾记录标识</param>

        /// <param name="clink">链接地址</param>

        /// <returns></returns>        

        public static string getPage(int recordCount, int pageSize, int pageNum, int pageIndex, out int beginIndex, out int endIndex, string clink)

        {

            int pcount = recordCount / pageSize;

            if (recordCount % pageSize > 0)

                pcount = pcount + 1;

            if (pageIndex < 1) pageIndex = 1;

            if (pageIndex > pcount) pageIndex = pcount;

 

            beginIndex = pageSize * (pageIndex - 1) + 1;

            endIndex = pageSize * pageIndex;

 

            int num = pageNum;    //中间显示页码数量

 

            string str = "";

 

            str = str + "共<span class=’pagecolorc’>" + recordCount + "</span>条记录 <span  class=’pagecolorc’>" + pageIndex + "</span> / <span  class=’pagecolorc’>" + pcount + "</span> 页  ";

 

            if (pcount > 1)

            {

 

                int wzleft, wzright, wzpagecount, wzcurrentpage, wzpagecountleft;

                wzcurrentpage = pageIndex;

                wzpagecount = pcount;

 

                if (wzcurrentpage < num)

                    wzleft = 0;

                else

                    wzleft = wzcurrentpage / num;

 

                wzright = wzcurrentpage % num;

 

                if (wzright == 0)

                    wzleft = wzleft - 1;

 

                if (wzcurrentpage - 1 > 0)

                    str = str + " <a class=’pagecolor pagenum’ href=’" + clink.Replace("[#p#]", (wzcurrentpage - 1).ToString()) + "’ title=’上一页’>上一页</a> ";

 

                if (wzcurrentpage > num)

                {

                    if (wzcurrentpage != 1 && wzcurrentpage > num)

                        str = str + " <a class=’pagecolor pagenum’ href=’" + clink.Replace("[#p#]","1") + "’>1</a> ";

 

                    str = str + " <a class=’pagecolor pagenum’ href=’" + clink.Replace("[#p#]", (wzleft * num).ToString()) + "’ title=’上一组’>...</a> ";

                }

 

                for (int i = 1; i <= num; i++)

                {

                    if (wzleft * num + i == wzcurrentpage)

                        str = str + " <a class=’pagecolorc pagecur’>" + (wzleft * num + i) + "</a> ";

                    else

                        str = str + " <a class=’pagecolor pagenum’ href=’" + clink.Replace("[#p#]", (wzleft * num + i).ToString()) + "’>" + (wzleft * num + i) + "</a> ";

 

                    if (wzleft * num + i == wzpagecount)

                        break;

                }

 

                wzpagecountleft = wzpagecount / num;

 

                if (wzpagecount % num == 0)

                    wzpagecountleft = wzpagecountleft - 1;

 

                if (wzleft < wzpagecountleft)

                {

                    str = str + " <a class=’pagecolor pagenum’ href=’" + clink.Replace("[#p#]", (wzleft * num + (pageNum + 1)).ToString()) + "’ title=’下一组’>...</a> ";

 

                    if (wzcurrentpage != wzpagecount && wzpagecount > num)

                        str = str + " <a class=’pagecolor pagenum’ href=’" + clink.Replace("[#p#]", wzpagecount.ToString()) + "’>" + wzpagecount + "</a> ";

                }

 

                if (wzcurrentpage + 1 <= pcount)

                    str = str + " <a class=’pagecolor pagenum’ href=’" + clink.Replace("[#p#]", (wzcurrentpage + 1).ToString()) + "’ title=’下一页’>下一页</a> ";

 

            }

 

            return str;

        }

 

    }
}

将以上代码添加到mPage.cs文件内,编译成dll就可以使用了。

也可以点击这里下载

也可以站内下载,点这里

版权所有,bubufx,禁止转载!

 

cPage分页源码,分享给大家,可作参考

上一篇:cPage源码


下一篇:ant 执行到javac时运行中止,怎么办?