通用分页实现(ASP版)
自己写的通用分页,可设置显示的分页链接数,带下拉选择:
1
<%
2
'Written by Shaoyun 20:17 2008年5月29日 0:38
3
'Email:shaoyun at yeah.net
4
'Blog:http://shaoyun.cnblogs.com
5
'分页函数:splitpage(记录总数,每页显示记录数,显示几条分页链接)
6
Function splitpage(rscount,pagesize,shownum)
7
8
Dim pagenum,curpage,first_page,last_page,up_page,down_page,idx,addr_url,splitpage_html
9
10
addr_url=Request.ServerVariables("URL")
11
addr_url=Mid(addr_url,InstrRev(addr_url,"/")+1)
12
addr_url=addr_url & "?page="
13
14
if (rscount mod pagesize)=0 then
15
pagenum=rscount/pagesize
16
else
17
pagenum=rscount/pagesize+1
18
end if
19
first_page=1
20
last_page=pagenum
21
22
curpage=1
23
if isnumeric(trim(request.QueryString("page"))) then
24
curpage=trim(request.QueryString("page"))
25
if pagenum-curpage<0 then curpage=pagenum
26
else
27
curpage=1
28
end if
29
30
up_page=curpage-1
31
down_page=curpage+1
32
33
splitpage_html="共$rscount$条记录 $pagesize$条/页 第$curpage$/$pagenum$页 "
34
splitpage_html=replace(splitpage_html,"$rscount$",rscount)
35
splitpage_html=replace(splitpage_html,"$pagesize$",pagesize)
36
splitpage_html=replace(splitpage_html,"$curpage$",curpage)
37
splitpage_html=replace(splitpage_html,"$pagenum$",pagenum)
38
39
splitpage_html=splitpage_html & "<a href='" & addr_url & first_page & "'>首页</a> "
40
if curpage>1 then
41
splitpage_html=splitpage_html & "<a href='" & addr_url & up_page & "'>上一页</a> "
42
else
43
splitpage_html=splitpage_html & "上一页 "
44
end if
45
46
dim fbegin,fend
47
if shownum mod 2 then
48
show_front_num=int(shownum/2)
49
show_back_num=int(shownum/2)
50
else
51
show_front_num=int(shownum/2)-1
52
show_back_num=int(shownum/2)
53
end if
54
if curpage-1<show_front_num then
55
fbegin=1
56
fend=shownum
57
elseif curpage+show_back_num>pagenum then
58
fend=pagenum
59
fbegin=pagenum-shownum+1
60
else
61
fbegin=curpage-show_front_num
62
fend=curpage+show_back_num
63
end if
64
for idx=fbegin to fend
65
if curpage-idx=0 then
66
splitpage_html=splitpage_html & "<b>" & idx & "</b> "
67
else
68
splitpage_html=splitpage_html & "<a href='" & addr_url & idx & "'>" & idx & "</a> "
69
end if
70
next
71
72
if pagenum-curpage>0 then
73
splitpage_html=splitpage_html & "<a href='" & addr_url & down_page & "'>下一页</a> "
74
else
75
splitpage_html=splitpage_html & "下一页 "
76
end if
77
splitpage_html=splitpage_html & "<a href='" & addr_url & last_page & "'>尾页</a> "
78
79
splitpage_html=splitpage_html & "跳转到 "
80
splitpage_html=splitpage_html & "<select onChange=window.location.href=this.options[this.selectedIndex].value>"
81
For idx=1 To pagenum
82
If curpage-idx=0 Then
83
splitpage_html=splitpage_html & "<option value='" & addr_url & idx & "' selected>第" & idx & "页</option>"
84
Else
85
splitpage_html=splitpage_html & "<option value='" & addr_url & idx & "'>第" & idx & "页</option>"
86
End if
87
Next
88
splitpage_html=splitpage_html & "</select>"
89
90
response.Write splitpage_html
91
92
End Function
93
%>
<%2
'Written by Shaoyun 20:17 2008年5月29日 0:383
'Email:shaoyun at yeah.net4
'Blog:http://shaoyun.cnblogs.com5
'分页函数:splitpage(记录总数,每页显示记录数,显示几条分页链接)6
Function splitpage(rscount,pagesize,shownum)7

8
Dim pagenum,curpage,first_page,last_page,up_page,down_page,idx,addr_url,splitpage_html9

10
addr_url=Request.ServerVariables("URL")11
addr_url=Mid(addr_url,InstrRev(addr_url,"/")+1)12
addr_url=addr_url & "?page="13

14
if (rscount mod pagesize)=0 then15
pagenum=rscount/pagesize16
else17
pagenum=rscount/pagesize+118
end if19
first_page=120
last_page=pagenum21

22
curpage=123
if isnumeric(trim(request.QueryString("page"))) then24
curpage=trim(request.QueryString("page"))25
if pagenum-curpage<0 then curpage=pagenum26
else27
curpage=128
end if29

30
up_page=curpage-131
down_page=curpage+132

33
splitpage_html="共$rscount$条记录 $pagesize$条/页 第$curpage$/$pagenum$页 "34
splitpage_html=replace(splitpage_html,"$rscount$",rscount)35
splitpage_html=replace(splitpage_html,"$pagesize$",pagesize)36
splitpage_html=replace(splitpage_html,"$curpage$",curpage)37
splitpage_html=replace(splitpage_html,"$pagenum$",pagenum)38

39
splitpage_html=splitpage_html & "<a href='" & addr_url & first_page & "'>首页</a> "40
if curpage>1 then41
splitpage_html=splitpage_html & "<a href='" & addr_url & up_page & "'>上一页</a> "42
else43
splitpage_html=splitpage_html & "上一页 "44
end if45

46
dim fbegin,fend47
if shownum mod 2 then48
show_front_num=int(shownum/2)49
show_back_num=int(shownum/2)50
else51
show_front_num=int(shownum/2)-152
show_back_num=int(shownum/2)53
end if54
if curpage-1<show_front_num then55
fbegin=156
fend=shownum57
elseif curpage+show_back_num>pagenum then58
fend=pagenum59
fbegin=pagenum-shownum+160
else61
fbegin=curpage-show_front_num62
fend=curpage+show_back_num63
end if64
for idx=fbegin to fend65
if curpage-idx=0 then 66
splitpage_html=splitpage_html & "<b>" & idx & "</b> "67
else68
splitpage_html=splitpage_html & "<a href='" & addr_url & idx & "'>" & idx & "</a> "69
end if70
next71

72
if pagenum-curpage>0 then73
splitpage_html=splitpage_html & "<a href='" & addr_url & down_page & "'>下一页</a> "74
else75
splitpage_html=splitpage_html & "下一页 "76
end if77
splitpage_html=splitpage_html & "<a href='" & addr_url & last_page & "'>尾页</a> "78

79
splitpage_html=splitpage_html & "跳转到 "80
splitpage_html=splitpage_html & "<select onChange=window.location.href=this.options[this.selectedIndex].value>"81
For idx=1 To pagenum82
If curpage-idx=0 Then83
splitpage_html=splitpage_html & "<option value='" & addr_url & idx & "' selected>第" & idx & "页</option>"84
Else85
splitpage_html=splitpage_html & "<option value='" & addr_url & idx & "'>第" & idx & "页</option>"86
End if87
Next88
splitpage_html=splitpage_html & "</select>"89

90
response.Write splitpage_html91

92
End Function93
%>
浙公网安备 33010602011771号