示例#1
0
        public string PageRender()
        {
            int           countpage = (int)Math.Ceiling((double)CountNum / CountPerPage);
            string        url       = UrlFormat.Replace("{&Page}", "&Page=");
            StringBuilder sb        = new StringBuilder();

            if (countpage <= displayNum)//总页数小于要显示的标签个数
            {
                for (int i = 1; i <= countpage; i++)
                {
                    if (i == CurrentPage)
                    {
                        sb.Append(i);
                    }
                    else
                    {
                        sb.Append("<a href=" + initURL(i) + ">" + i + "</a>");
                    }
                }
            }
            else
            {
                sb.Append("<a class='doublePage' href=" + initURL(1) + ">" + "首" + "</a>");
                if (CurrentPage != 1)
                {
                    sb.Append("<a class='doublePage' href=" + initURL(CurrentPage - 1) + ">" + "前" + "</a>");
                }
                for (int i = 1; i <= displayNum; i++)
                {
                    if (CurrentPage < (int)Math.Ceiling((double)displayNum / 2))
                    {
                        if (i == CurrentPage)//当前页的输出不带超键接
                        {
                            sb.Append(CurrentPage);
                        }
                        else
                        {
                            sb.Append("<a href=" + initURL(i) + ">" + i + "</a>");
                        }
                    }
                    else if ((int)(countpage - CurrentPage) < (int)Math.Ceiling((double)displayNum / 2))
                    {
                        if (countpage - displayNum + i == CurrentPage)//当前页的输出不带超键接
                        {
                            sb.Append(CurrentPage);
                        }
                        else
                        {
                            sb.Append("<a href=" + initURL(countpage - displayNum + i) + ">" + (countpage - displayNum + i) + "</a>");
                        }
                    }
                    else
                    {
                        if ((CurrentPage - (int)Math.Ceiling((double)displayNum / 2) + i) == CurrentPage)
                        {
                            sb.Append(CurrentPage);
                        }
                        else
                        {
                            sb.Append("<a href=" + initURL(CurrentPage - (int)Math.Ceiling((double)displayNum / 2) + i) + ">" + (CurrentPage - (int)Math.Ceiling((double)displayNum / 2) + i) + "</a>");
                        }
                    }
                }
                if (CurrentPage != countpage)
                {
                    sb.Append("<a class='doublePage'  href=" + initURL(CurrentPage + 1) + ">" + "后" + "</a>");
                }
                sb.Append("<a class='doublePage' href=" + initURL(countpage) + ">" + "末" + "</a>");
            }

            return(sb.ToString());
        }
示例#2
0
 }                                   //要显示的页面标签条数(不包括首页,前页,后页和尾页)
 private string initURL(int i)
 {
     return(UrlFormat.Replace("{&Page}", "&Page=" + i));
 }