自定义后台分页(1)
/// <summary> /// 自定义后台分页 /// </summary> /// <param name="PageName">Url地址</param> /// <param name="PageExt">带参数</param> /// <param name="count">总数</param> /// <param name="page">当前页面</param> /// <param name="pagesize">每页显示多少条</param> /// <returns></returns> public static string GetPageUrl(string PageName, string PageExt, int count, int page, int pagesize) { string pageNumText = "pageNumText_" + new Random().Next(0, 100) + "_" + DateTime.Now.ToString("yyyyMMddHHmmss"); int pagecount = 0; if (count % pagesize == 0) pagecount = count / pagesize; else pagecount = count / pagesize + 1; StringBuilder url = new StringBuilder(""); if (pagecount > 1) { url.Append("<div class=\"manu\"><div id=\"AspNetPager1\">"); url.Append("<div class=\"apl\">第" + page + "页/总" + pagecount + "页 [每页" + pagesize + "条/共" + count + "条记录]"); url.AppendFormat("<span><input id='{1}' type='text' value='{0}' class='pageNumText' style='width:30px;' />", page, pageNumText); url.AppendFormat("<input type='button' value='go' class='gopagebtn' onclick='(function(){{window.location.href =\"{0}?page=\"+document.getElementById(\"{2}\").value+\"{1}\";}})()' /></span>", PageName, PageExt, pageNumText); url.Append("</div><div class='apr'>"); if (page > 1) { url.Append("<span class=\"span1\"><a href=\"" + PageName + "?page=1" + PageExt + "\" style=\"margin-right:5px;\">首页</a></span>"); url.Append("<span class=\"span1\"><a href=\"" + PageName + "?page=" + (page - 1) + PageExt + "\" style=\"margin-right:5px;\"><上一页</a></span>"); } else { url.Append("<span class=\"span1\"><a disabled=\"true\" style=\"margin-right:5px;\">首页</a></span>"); } int min = 0, max = 0; min = page - 5; if (min < 1) min = 1; max = page + 5; if (max < 10) max = 10; if (max > pagecount) max = pagecount; for (int i = min; i <= max; i++) { if (i == page) { url.Append("<span class=\"span0\">" + i + "</span>"); } else { url.Append("<span class=\"span1\"><a href=\"" + PageName + "?page=" + i + PageExt + "\" style=\"margin-right:5px;\">" + i + "</a></span>"); } } if (page < pagecount) { url.Append("<span class=\"span1\"><a href=\"" + PageName + "?page=" + (page + 1) + PageExt + "\" style=\"margin-right:5px;\">下一页></a></span>"); url.Append("<span class=\"span1\"><a href=\"" + PageName + "?page=" + pagecount + PageExt + "\" style=\"margin-right:5px;\">尾页</a></span>"); } url.Append("</div></div></div>\r\n");//</td></tr></table> } return url.ToString(); }
1 2 3 4 5 6 7 | 实例 string url= "Default.aspx" ; string pageEx = "&key=" + key + "&name=" + name + "&class0=" + class0 + "; int page=1; int pagesize=5; GetPageUrl(url, pageEx, count, page, pagesize) |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步