当前位置:编程学习 > C#/ASP.NET >>

.net B/S 结构 数据分页,如果页太多用...代替,的实现思路及代码

<< 1 2 3 4 5 …… 9 10 >>  这种的分页类,不用控件 --------------------编程问答-------------------- public static string getPagelist(int totalCount, int apagecount, int nowPage, int gepage, string filename, System.Web.UI.WebControls.DropDownList DropDlist)
        {
            int pageCount = totalCount / apagecount;
            if (totalCount % apagecount > 0)
                pageCount++;


            string pageTxt = null;
            int prepage = nowPage - 1, nextpage = nowPage + 1, startpage = 0;
            if (prepage < 1)
            {
                pageTxt += "<span class=\"nocss\">First</span> <span class=\"nocss\">Prew</span>";
            }
            else
            {
                pageTxt += "<span ><a href=\"" + filename + "/page.1~totalcounts." + totalCount + CheckReuest("page") + "\">First</a></span> <span ><a href=\"" + filename + "/page." + prepage.ToString() + "~totalcounts." + totalCount + CheckReuest("page") + "\">Prew</a></span> ";
            }

            if (nowPage % gepage == 0)
            {
                startpage = nowPage - 9;
            }
            else
            {
                startpage = nowPage - nowPage % gepage + 1;
            }

            if (startpage > gepage)
            {
                pageTxt += " <span><a href=\"" + filename + "/page." + (startpage - 1).ToString() + "~totalcounts." + totalCount + CheckReuest("page") + "\">...</a></span>";
            }

            for (int i = startpage; i < startpage + gepage; i++)
            {
                if (i > pageCount) break;
                if (i == nowPage)
                {
                    pageTxt += "<span class=\"atcss\">" + i.ToString() + "</span>";
                }
                else
                {
                    pageTxt += "<span><a href=\"" + filename + "/page." + i.ToString() + "~totalcounts." + totalCount + CheckReuest("page") + "\">" + i.ToString() + "</a></span>";
                }
            }

            if (pageCount >= startpage + gepage)
                pageTxt += "<span ><a href=\"" + filename + "/page." + (startpage + gepage).ToString() + "~totalcounts." + totalCount + CheckReuest("page") + "\">...</a></span>";

            if (nextpage > pageCount)
            {
                pageTxt += "<span  class=\"nocss\">Next</span> <span  class=\"nocss\">Last</span>";
            }
            else
            {
                pageTxt += "<span ><a href=\"" + filename + "/page." + nextpage.ToString() + "~totalcounts." + totalCount + CheckReuest("page") + "\">Next</a></span> <span><a href=\"" + filename + "/page." + pageCount.ToString() + "~totalcounts." + totalCount + CheckReuest("page") + "\">Last</a></span>";
            }

            if (DropDlist != null)
            {
                DropDlist.Items.Clear();
                for (int i = 0; i < pageCount; i++)
                {
                    DropDlist.Items.Insert(i, new ListItem((i + 1).ToString(), (i + 1).ToString()));
                }
                DropDlist.SelectedValue = nowPage.ToString();
            }

            return pageTxt;
        }
--------------------------------------------
自己更改一下吧。
--------------------编程问答--------------------
引用 1 楼 lovelium 的回复:
public static string getPagelist(int totalCount, int apagecount, int nowPage, int gepage, string filename, System.Web.UI.WebControls.DropDownList DropDlist)
  {
  int pageCount = totalCount / apagec……

写个注释吧,好懂一点,嘿嘿 --------------------编程问答-------------------- gepage 这个字段是什么意思啊。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,