| 今天我写了个分页函数(ASP+ACCESS),之前在网上搜了下,很多,但是好多都是一大堆的代码,有的的确很强大,杀鸡焉用宰牛刀,所以自己写了个,代码没几行,但是速度也很快。一百万条数据,页面执行时间也就几十毫秒。
我写的这个函数,显示效果有两种。第一种就是5页内,页码左右有“上一页”和“下一页”;第二种是超过5页,页码左右是“前5页”和“后5页”。效果图如下图:
< % Function pagination(pagecount) dim myPage,myPageCount,PageNum if Len(Request.QueryString("page"))<>0 then myPage = clng(Request.QueryString("page")) else myPage =1 End if if myPage <= 0 then myPage =1 PageNum = (myPage \ 5)*5+1 if myPage mod 5 = 0 then PageNum = (myPage \ 5)*5-4
if myPage <= pagecount then if myPage > 5 then Response.Write ("< a href="http://www.ygblog.com/"?page=1"">首页") Response.Write (" < a href="http://www.ygblog.com/"?page="& PageNum-1 &""">前5页") elseif myPage > 1 and pagecount <= 5 then Response.Write ("< a href="http://www.ygblog.com/"?page="& myPage-1 &""">上一页") End if
for PageNum = PageNum To PageNum + 4 if PageNum = myPage then Response.Write (" < strong>["& PageNum &"]< /strong>") else Response.Write (" < a href="http://www.ygblog.com/"?page="& PageNum &""">") Response.Write ("["& PageNum &"]") Response.Write ("") End if if PageNum >= pagecount then Exit for Next End if
if myPage <= (pagecount - (pagecount mod 5)) and pagecount > 5 then Response.Write (" < a href="http://www.ygblog.com/"?page="& PageNum &""">后5页") Response.Write (" < a href="http://www.ygblog.com/"?page="& pagecount &""">末页") elseif myPage < pagecount and pagecount <= 5 then Response.Write (" < a href="http://www.ygblog.com/"?page="& myPage+1 &""">下一页") End if End Function % >
有需要的朋友可以联系我免费索取
|