這是我asp程序中最常用,最通用的一個ASP分頁函數,適合所有表,在整個網站的開發過程中,只用這一個就可以解決所有分頁問題,並且允許帶入不同的參數。
01
'功能:常用的ASP分頁函數
02
'開發:<a href="http://www.aspbc.com">www.ASPbc.com</a> '作者:wangsdong
03
'原創文章,轉載請保存此信息
04
'參數含義:
05
'page當前頁
06
'page_size每頁總數
07
'recordset_count總數
08
'str字符串
09
Function fpage(page,page_size,recordset_count,str)
10
If recordset_count=0 Or IsNull(recordset_count) Then Exit function
11
If str<>"" then
12
s=Split(str,"|")
13
s2=""
14
For i=0 To UBound(s)
15
s2=s2&"&"&s(i)&"="&server.URLEncode(request(s(i)))
16
Next
17
End If
18
Dim str9
19
str9=""
20
page=CInt(page)
21
if recordset_count mod page_size=0 then
22
page_count=recordset_count\page_size
23
else
24
page_count=recordset_count\page_size+1
25
end if
26
27
str9=str9&"<a href=""?page=1"&s2&""">首頁</a> "
28
if page>4 then
29
s=page-3
30
else
31
s=1
32
end if
33
if page<=page_count-3 then
34
e=page+3
35
else
36
e=page_count
37
end if
38
for i=s to e
39
if i=page then
40
str9=str9&"<b>"&i&"</b> "
41
else
42
str9=str9&"<a href=""?page="&i&s2&""">"&i&"</a> "
43
end if
44
Next
45
46
str9=str9&"<a href=""?page="&page_count&s2&""">末頁</a> <span>第 (<span class=""cRed"">"&page&"</span>/<span class=""cTotal"">"&page_count&"</span>) 頁</span>"
47
fpage=str9
48
End Function(鼠標移到代碼上去,在代碼的頂部會出現四個圖標,第一個是查看源代碼,第二個是復制代碼,第三個是打印代碼,第四個是幫助)01
'先得到符合條件的記錄總數
02
'地址如:http://www.aspbc.com/list.ASP 後面沒有參數
03
sql="select count(*) as num from table where ……"
04
countnum=conn.execute(sql)
05
'然後調用這個函數
06
page=request("page") ’得到當前頁數
07
if page="" then page=1
08
page_size=10 '當前每頁10條
09
str="" '不傳參數,也就是地址欄沒有參數
10
'調用函數
11
response.write fpage(page,page_size,count,str)(鼠標移到代碼上去,在代碼的頂部會出現四個圖標,第一個是查看源代碼,第二個是復制代碼,第三個是打印代碼,第四個是幫助)