直接写成函数的形式,如果输出生成好的页码,然后又程序输出或保存到文件中。
前十页为一批,第十页显示1,2,3…10;第十一页页码就变成了11,12…20
这种模式很多CMS都用到,比如5UCMS。函数名留点版权信息吧,cs=CatSeven
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
<% function csPage(id,all,url1,url2) if id<>1 then tmp= "<a href=" "" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" &url1& "1" &url2& "" ">首页</a> <a href=" "" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" &url1&id-1&url2& "" ">上一页</a>" istart=((id-1)\10)*10+1 if(all-id)>9 then iend=((id-1)\10)*10+10 else iend=all end if for i=istart to iend if i=id then tmp=tmp& "<span>" &i& "</span> " else tmp=tmp& "<a href=" "" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" &url1&i&url2& "" ">" &i& "</a> " end if next if id<>all then tmp=tmp& "<a href=" "" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" &url1&id+1&url2& "" ">下一页</a> <a href=" "" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" &url1&all&url2& "" ">尾页</a>" csPage=tmp end function 'DEBUG for j=1 to 40 response.write "#Page" &j& ":" &csPage(j,40, "#TEST_" , "_View" )& "<br />" next %> |
生成效果如下:
#Page1:1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page2:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page3:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page4:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page5:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page6:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page7:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page8:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page9:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page10:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page11:首页 上一页 11 12 13 14 15 16 17 18 19 20 下一页 尾页
#Page12:首页 上一页 11 12 13 14 15 16 17 18 19 20 下一页 尾页
#Page13:首页 上一页 11 12 13 14 15 16 17 18 19 20 下一页 尾页
#Page14:首页 上一页 11 12 13 14 15 16 17 18 19 20 下一页 尾页
#Page15:首页 上一页 11 12 13 14 15 16 17 18 19 20 下一页 尾页
#Page16:首页 上一页 11 12 13 14 15 16 17 18 19 20 下一页 尾页
#Page17:首页 上一页 11 12 13 14 15 16 17 18 19 20 下一页 尾页
#Page18:首页 上一页 11 12 13 14 15 16 17 18 19 20 下一页 尾页
#Page19:首页 上一页 11 12 13 14 15 16 17 18 19 20 下一页 尾页
#Page20:首页 上一页 11 12 13 14 15 16 17 18 19 20 下一页 尾页
#Page21:首页 上一页 21 22 23 24 25 26 27 28 29 30 下一页 尾页
#Page22:首页 上一页 21 22 23 24 25 26 27 28 29 30 下一页 尾页
#Page23:首页 上一页 21 22 23 24 25 26 27 28 29 30 下一页 尾页
#Page24:首页 上一页 21 22 23 24 25 26 27 28 29 30 下一页 尾页
#Page25:首页 上一页 21 22 23 24 25 26 27 28 29 30 下一页 尾页
#Page26:首页 上一页 21 22 23 24 25 26 27 28 29 30 下一页 尾页
#Page27:首页 上一页 21 22 23 24 25 26 27 28 29 30 下一页 尾页
#Page28:首页 上一页 21 22 23 24 25 26 27 28 29 30 下一页 尾页
#Page29:首页 上一页 21 22 23 24 25 26 27 28 29 30 下一页 尾页
#Page30:首页 上一页 21 22 23 24 25 26 27 28 29 30 下一页 尾页
#Page31:首页 上一页 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page32:首页 上一页 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page33:首页 上一页 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page34:首页 上一页 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page35:首页 上一页 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page36:首页 上一页 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page37:首页 上一页 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page38:首页 上一页 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page39:首页 上一页 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page40:首页 上一页 31 32 33 34 35 36 37 38 39 40
说实话我并不是很喜欢这种分页方式,我比较喜欢上次写的那个。
如果不超过10页,比如共5页。1,2,3,4,5;
如果最末页减当前页码不超过十,页码显示最后10页;
其他的是前四后五的方法。直接给出代码吧
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
function csPage1(id,all,url1,url2) if id<>1 then tmp= "<a href=" "" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" &url1& "1" &url2& "" ">首页</a> <a href=" "" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" &url1&id-1&url2& "" ">上一页</a> " if all<10 or id<10 then istart=1 if all<10 then iend=all else iend=10 elseif all-id<10 then istart=all-10 iend=all else istart=id-4 iend=id+5 end if for i=istart to iend if i=id then tmp=tmp& "<span>" &i& "</span> " else tmp=tmp& "<a href=" "" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" &url1&i&url2& "" ">" &i& "</a> " end if next if id<>all then tmp=tmp& "<a href=" "" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" &url1&id+1&url2& "" ">下一页</a> <a href=" "" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" &url1&all&url2& "" ">尾页</a>" csPage1=tmp end function for j=1 to 40 response.write "#Page" &j& ":" &csPage1(j,40, "#TEST_" , "_View" )& "<br />" next |
生成效果如下:
#Page1:1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page2:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page3:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page4:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page5:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page6:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page7:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page8:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page9:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页
#Page10:首页 上一页 6 7 8 9 10 11 12 13 14 15 下一页 尾页
#Page11:首页 上一页 7 8 9 10 11 12 13 14 15 16 下一页 尾页
#Page12:首页 上一页 8 9 10 11 12 13 14 15 16 17 下一页 尾页
#Page13:首页 上一页 9 10 11 12 13 14 15 16 17 18 下一页 尾页
#Page14:首页 上一页 10 11 12 13 14 15 16 17 18 19 下一页 尾页
#Page15:首页 上一页 11 12 13 14 15 16 17 18 19 20 下一页 尾页
#Page16:首页 上一页 12 13 14 15 16 17 18 19 20 21 下一页 尾页
#Page17:首页 上一页 13 14 15 16 17 18 19 20 21 22 下一页 尾页
#Page18:首页 上一页 14 15 16 17 18 19 20 21 22 23 下一页 尾页
#Page19:首页 上一页 15 16 17 18 19 20 21 22 23 24 下一页 尾页
#Page20:首页 上一页 16 17 18 19 20 21 22 23 24 25 下一页 尾页
#Page21:首页 上一页 17 18 19 20 21 22 23 24 25 26 下一页 尾页
#Page22:首页 上一页 18 19 20 21 22 23 24 25 26 27 下一页 尾页
#Page23:首页 上一页 19 20 21 22 23 24 25 26 27 28 下一页 尾页
#Page24:首页 上一页 20 21 22 23 24 25 26 27 28 29 下一页 尾页
#Page25:首页 上一页 21 22 23 24 25 26 27 28 29 30 下一页 尾页
#Page26:首页 上一页 22 23 24 25 26 27 28 29 30 31 下一页 尾页
#Page27:首页 上一页 23 24 25 26 27 28 29 30 31 32 下一页 尾页
#Page28:首页 上一页 24 25 26 27 28 29 30 31 32 33 下一页 尾页
#Page29:首页 上一页 25 26 27 28 29 30 31 32 33 34 下一页 尾页
#Page30:首页 上一页 26 27 28 29 30 31 32 33 34 35 下一页 尾页
#Page31:首页 上一页 30 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page32:首页 上一页 30 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page33:首页 上一页 30 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page34:首页 上一页 30 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page35:首页 上一页 30 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page36:首页 上一页 30 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page37:首页 上一页 30 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page38:首页 上一页 30 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page39:首页 上一页 30 31 32 33 34 35 36 37 38 39 40 下一页 尾页
#Page40:首页 上一页 30 31 32 33 34 35 36 37 38 39 40
上面的代码在2009-2010年写过简单个两个分页(调取页码的函数):
现在看有点乱了,最近有重新整理了下代码,重写了ASP的分页代码,生成的分页代码兼容BootStrap。代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
'PageinationRecordSet 如果返回false,说明 Adodb.RecrodSet集 为空 'RecordSet Adodb.RecrodSet集 'PageId 当前所在页 'PageSize 每页显示多少条? '*PageCount 返回页码总数 function PageinationRecordSet(byref RecordSet,byref PageId,byval PageSize,byref PageCount) if RecordSet.eof then PageinationRecordSet = false else RecordSet.PageSize = PageSize PageCount = RecordSet.PageCount if PageId > PageCount then PageId = PageCount RecordSet.absolutePage = PageId PageinationRecordSet = true end if end function 'PageId 当前所在页 'PageCount 页码总数 'urlTemplate 链接模板 function PageinationPageList(byval PageId,byval PageCount,byval urlTemplate) dim codeTemp,iPage if PageCount > 0 then codeTemp = "<ul class=" "pagination" ">" if PageId <= 1 then codeTemp = codeTemp & "<li class=" "disabled" ">" else codeTemp = codeTemp & "<li>" codeTemp = codeTemp & "<a href=" "" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" & replace(urlTemplate, "{pg}" ,1) & "" "> 首页 </a></li>" if PageId <= 1 then codeTemp = codeTemp & "<li class=" "disabled" ">" else codeTemp = codeTemp & "<li>" codeTemp = codeTemp & "<a href=" "" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" & replace(urlTemplate, "{pg}" ,PageId-1) & "" ">上一页</a></li>" for iPage = PageId - 5 to PageId + 5 if iPage = PageId then codeTemp = codeTemp & "<li class=" "active" "><a href=" "" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" & replace(urlTemplate, "{pg}" ,iPage) & "" ">" & iPage & "</a></li>" elseif iPage < PageId and iPage > 0 then codeTemp = codeTemp & "<li><a href=" "" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" & replace(urlTemplate, "{pg}" ,iPage) & "" ">" & iPage & "</a></li>" elseif iPage > PageId and iPage <= PageCount then codeTemp = codeTemp & "<li><a href=" "" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" & replace(urlTemplate, "{pg}" ,iPage) & "" ">" & iPage & "</a></li>" end if next if PageId >= PageCount then codeTemp = codeTemp & "<li class=" "disabled" ">" else codeTemp = codeTemp & "<li>" codeTemp = codeTemp & "<a href=" "" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" & replace(urlTemplate, "{pg}" ,PageId + 1) & "" ">下一页</a></li>" if PageId >= PageCount then codeTemp = codeTemp & "<li class=" "disabled" ">" else codeTemp = codeTemp & "<li>" codeTemp = codeTemp & "<a href=" "" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" & replace(urlTemplate, "{pg}" ,PageCount) & "" ">尾页</a></li>" PageinationPageList = codeTemp & "</ul>" end if end function |
测试代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
pgId = Request.QueryString( "pageid" ) '当前页码 pgSize = 10 '每页大小 rsId = 0 Rs.Open Query,Conn,1,1 if PageinationRecordSet(Rs, pgId, pgSize, pgCount) then do while not Rs.Eof and rsId < pgSize rsId = rsId + 1 '列表内容 Rs.MoveNext loop end if Rs.Close '共 pgCount 页 response.write PageinationPageList(pgId, pgCount, "./list.asp?pageid={pg}" ) '输出分页代码 |
到此这篇关于完美的ASP分页脚本代码的文章就介绍到这了,更多相关ASP分页内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:http://www.miaoqiyuan.cn/p/asp-pageination