cPage分頁源碼,分享給你們,可做參考

cPage是asp.net分頁控件,也能夠叫作分頁組件,更確切的應該叫作分頁模塊,也或者叫作分頁通用代碼。html

cPage,版本3.2,源碼以下:asp.net

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就可使用了。spa

也能夠點擊這裏下載.net

也能夠站內下載,點這裏code

版權全部,bubufx,禁止轉載!htm

相關文章
相關標籤/搜索