分頁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();
        }


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章