搞了一天,终于搞出属于自己的数字导航条分页类,哈哈……,通用的!! using System; public partial class MyCeShiPage : System.Web.UI.Page if (this.Request.Params["currentPage"] == null) public static int pages; //总的页数 } //分页条分三部分,leftInfo是最左边的部分,用来显示当前页/总页数,每页显示的记录条数 leftInfo = "第" + currentpage +"页"+ "/" + "共"+pages+"页" + " " + "每页" int min;//要显示的页面数最小值 int max;//要显示的页面数最大值 if (currentpage > pages)//当前页必须小于最大页 if (currentpage % showpage == 0) //如果恰好整除 min = currentpage + 1; max = currentpage + showpage; min = (((int)currentpage / showpage) - 1) * showpage + 1; max = currentpage - 1; } else min = ((int)currentpage / showpage) * showpage + 1; max = (((int)currentpage / showpage) + 1) * showpage; } string numberStr = " ";//循环生成数字序列部分 string AbsUrl;//(URL?)左边的部分 AbsUrl = this.Context.Request.Url.ToString(); if (AbsUrl.IndexOf("?") == -1) } else AbsUrl = AbsUrl.Substring(0, AbsUrl.IndexOf("?")); }
if (i <= pages)//只有不大于最大页才显示 if (currentpage == i)//如果是当前页,用斜体和红色显示 numberStr = numberStr + "<a href=" + AbsUrl + "?currentPage=" + i.ToString() + ">" + "<I style='color:red'>" + i.ToString() + "</I>" + "</a>" + "/n"; } else numberStr = numberStr + "<a href=" + AbsUrl + "?currentPage=" + i.ToString() + ">" + i.ToString() + "</a>" + "/n"; } } }
string First, Previous, Next, Last; First = AbsUrl + "?currentPage=1"; ///////// if (currentpage == 1) Previous = AbsUrl + "?currentPage=1"; else Previous = AbsUrl + "?currentPage=" + (currentpage - 1).ToString(); ///////// if (currentpage == pages) Next = AbsUrl + "?currentPage=" + pages; else Next = AbsUrl + "?currentPage=" + (currentpage + 1).ToString(); Last = AbsUrl + "?currentPage=" + pages; centerInfo.AppendFormat("<font face='Webdings' style='font-size:14px'><a href="/{0"}>7</a><a href="/{1"}>3</a></font>{2}<font face='Webdings' style='font-size:14px'><a href="/{3"}>4</a><a href="/{4"}>8</a></font>", First, Previous, numberStr, Next, Last); StringBuilder sb = new StringBuilder();//输出HTML字符串 sb.AppendFormat("<table style = 'font-size:12px' border='0' cellpadding='0' cellspacing='0' width='100%'> /n " + "<tr>/n" + "<td width='25%' align='left'>{0}</td>/n" + "<td width='61%' align='right'>{1}</td>/n" + "<td width='14%' align='right'><input type='text' name='T1' size='4' style='border-bottom:solid 1pt gray;border-top :solid 1pt gray; border-left:solid 1pt gray;border-right:solid 1pt gray;'> /n <input type='button' name='B1' size='6' value=go style='border-bottom:solid 1pt gray;border-top :solid 1pt gray; border-left:solid 1pt gray;border-right:solid 1pt gray;' onclick='go(T1,{2})'></td>/n" + "</tr>/n" + "</table>", leftInfo, centerInfo.ToString(), pages);
//} public int CalculateRecord() //计算总共有多少条记录 |
自己用asp.net 搞的数字导航条分页
最新推荐文章于 2014-03-25 20:40:00 发布