分页HTML代码

public string RetureHtml()
        {
            int PageCount = Count % Number == 0 ? Convert.ToInt32(Count / Number) : Convert.ToInt32(Count / Number) + 1;
            int ShowPageCount = Convert.ToInt32(this.ShowPageCount / 2);
            url = url.ToLower();
            PageName = PageName.ToLower();
            if (IsCustom == false)
            {
                url = url + "?";
                for (int i = 0; i < HttpContext.Current.Request.QueryString.Count; i++)
                {
                    if (HttpContext.Current.Request.QueryString.AllKeys[i] != PageName)
                        url = url + HttpContext.Current.Request.QueryString.AllKeys[i] +"="+ HttpContext.Current.Request.QueryString[i]+"&";
                }
                url = url + PageName + "=";
            }
            StringBuilder str = new StringBuilder();
            if (Page >= 1 && Page <= PageCount)
            {
                if (Number < Count)
                {
                    str.Append("<div class=\"" + DClassName + "\">");
                    if (Page > ShowPageCount && PageCount > this.ShowPageCount)
                        str.Append("<a href=\"" + (IsCustom == true ? url.Replace(PageName, "1") : (url + "1")) + "\">1</a>");
                    if (Page > ShowPageCount && PageCount > this.ShowPageCount)
                    {
                        str.Append("<a href=\"" + (IsCustom == true ? url.Replace(PageName, (Page - ShowPageCount).ToString()) : (url + (Page - ShowPageCount))) + "\">...</a>");
                    }

                    if (PageCount <= this.ShowPageCount)
                    {
                        for (int i = 1; i <= PageCount; i++)
                        {
                            if (i != Page)
                                str.Append("<a href=\"" + (IsCustom == true ? url.Replace(PageName, i.ToString()) : (url + i)) + "\">" + i + "</a>");
                            else
                                str.Append("<span class=\"" + SClassName + "\">" + i + "</span>");
                        }
                    }
                    else
                    {
                        if (Page <= ShowPageCount || Page >= (PageCount - ShowPageCount))
                        {
                            if (Page <= ShowPageCount)
                            {
                                for (int i = 1; i <= this.ShowPageCount; i++)
                                {
                                    if (i != Page)
                                        str.Append("<a href=\"" + (IsCustom == true ? url.Replace(PageName, i.ToString()) : (url + i)) + "\">" + i + "</a>");
                                    else
                                        str.Append("<span class=\"" + SClassName + "\">" + i + "</span>");
                                }
                            }
                            else
                            {
                                for (int i = 1; i <= this.ShowPageCount; i++)
                                {
                                    if (i != this.ShowPageCount - (PageCount - Page))
                                        str.Append("<a href=\"" + (IsCustom == true ? url.Replace(PageName, (PageCount - this.ShowPageCount + i).ToString()) : (url + (PageCount - this.ShowPageCount + i))) + "\">" + (PageCount - this.ShowPageCount + i) + "</a>");
                                    else
                                        str.Append("<span class=\"" + SClassName + "\">" + Page + "</span>");
                                }
                            }
                        }
                        else
                        {
                            for (int i = 1; i <= this.ShowPageCount; i++)
                            {
                                if (i != ShowPageCount)
                                    str.Append("<a href=\"" + (IsCustom == true ? url.Replace(PageName, (Page - ShowPageCount + i).ToString()) : (url + (Page - ShowPageCount + i))) + "\">" + (Page - ShowPageCount + i) + "</a>");
                                else
                                    str.Append("<span class=\"" + SClassName + "\">" + Page + "</span>");
                            }
                        }
                    }


                    if (PageCount - Page > ShowPageCount && PageCount > this.ShowPageCount)
                    {
                        str.Append("<a href=\"" + (IsCustom == true ? url.Replace(PageName, (Page + ShowPageCount).ToString()) : (url + (Page + ShowPageCount))) + "\">...</a>");
                    }
                    if (PageCount - Page > ShowPageCount && PageCount > this.ShowPageCount)
                        str.Append("<a href=\"" + (IsCustom == true ? url.Replace(PageName, PageCount.ToString()) : (url + PageCount)) + "\">" + PageCount + "</a>");

                    str.Append("</div>");
                }
                else
                {
                    str.Append("<div class=\"" + DClassName + "\">");
                    str.Append("<span class=\"" + SClassName + "\">1</span>");
                    str.Append("</div>");
                }
            }
            return str.ToString();
        }


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值