c# 后台拼接分页Html

2021-07-09 04:09

阅读:427

标签:fir   public   ges   turn   app   color   分页   ring   计算   

  public static string ReplaceStr(string originalStr, string oldStr, string newStr)
        {
            if (string.IsNullOrEmpty(oldStr))
            {
                return "";
            }
            return originalStr.Replace(oldStr, newStr);
        }
  public static string OutPageList(int pageSize, int pageIndex, int totalCount, string linkUrl, int centSize)
        {
            //计算页数
            if (totalCount 1 || pageSize 1)
            {
                return "";
            }
            int pageCount = totalCount / pageSize;
            if (pageCount 1)
            {
                return "";
            }
            if (totalCount % pageSize > 0)
            {
                pageCount += 1;
            }
            if (pageCount 1)
            {
                return "";
            }
            StringBuilder pageStr = new StringBuilder();
            string pageId = "__id__";
            string firstBtn = "" + ReplaceStr(linkUrl, pageId, (pageIndex - 1).ToString()) + "\">?上一页";
            string lastBtn = "" + ReplaceStr(linkUrl, pageId, (pageIndex + 1).ToString()) + "\">下一页?";
            string firstStr = "" + ReplaceStr(linkUrl, pageId, "1") + "\">1";
            string lastStr = "" + ReplaceStr(linkUrl, pageId, pageCount.ToString()) + "\">" + pageCount.ToString() + "";

            if (pageIndex 1)
            {
                firstBtn = "?上一页";
            }
            if (pageIndex >= pageCount)
            {
                lastBtn = "下一页?";
            }
            if (pageIndex == 1)
            {
                firstStr = "1";
            }
            if (pageIndex == pageCount)
            {
                lastStr = "" + pageCount.ToString() + "";
            }
            int firstNum = pageIndex - (centSize / 2); //中间开始的页码
            if (pageIndex  centSize)
                firstNum = 2;
            int lastNum = pageIndex + centSize - ((centSize / 2) + 1); //中间结束的页码
            if (lastNum >= pageCount)
                lastNum = pageCount - 1;
            pageStr.Append("" + totalCount + "记录");
            pageStr.Append(firstBtn + firstStr);
            if (pageIndex >= centSize)
            {
                pageStr.Append("...\n");
            }
            for (int i = firstNum; i )
            {
                if (i == pageIndex)
                {
                    pageStr.Append("" + i + "");
                }
                else
                {
                    pageStr.Append("" + ReplaceStr(linkUrl, pageId, i.ToString()) + "\">" + i + "");
                }
            }
            if (pageCount - pageIndex > centSize - ((centSize / 2)))
            {
                pageStr.Append("...");
            }
            pageStr.Append(lastStr + lastBtn);
            return pageStr.ToString();
        }

 

c# 后台拼接分页Html

标签:fir   public   ges   turn   app   color   分页   ring   计算   

原文地址:https://www.cnblogs.com/yuanzijian-ruiec/p/9720873.html


评论


亲,登录后才可以留言!