这个程序将显示翻页连接功能单独抽出,而不涉及其它操作,可内置翻页效果,方便灵活。
pagehanshu.asp
<%
’设置页码及URL
’value1 翻页地址
’value2 page的值
’value3 地址标签 eg:第一页、下一页
’value4 根据vaule1而定
’如果 value1 = "page.asp" 时,value4 = 1; value1 = "page.asp?id=1" 时,value4 = 0;
function page_url(value1,value2,value3,value4)
dim result
dim val
if value4 = 1 then
val = "?"
else
val = "&"
end if
result = "" & value3 & ""
page_url = result
end function
’取得翻页的page参数 即为当前页
function page_request()
dim page
page = request("page")
if ( page <> "" and IsNumeric(page) = false ) or page = "" then
page = 1
end if
page_request = page
end function
’设置最常用的翻页模式,任意添加和修改
’第一种效果 写的有点繁琐
’n为总页数
function pagemode1(value1,value2)
dim out
val1 = value1
val4 = value2
page = page_request()
page = CInt(page)
val2_1 = 1
val2_2 = page - 1
val2_3 = page + 1
val2_4 = n
val3_1 = "第一页"
val3_2 = "上一页"
val3_3 = "下一页"
val3_4 = "最后页"
if page = 1 then
out1 = val3_1
out2 = val3_2
else
out1 = page_url(val1,val2_1,val3_1,val4)
out2 = page_url(val1,val2_2,val3_2,val4)
end if
if page = n then
out3 = val3_3
out4 = val3_4
else
out3 = page_url(val1,val2_3,val3_3,val4)
out4 = page_url(val1,val2_4,val3_4,val4)
end if
out = out1 & " " & out2 & " " & out3 & " " & out4
pagemode1 = out
end function
’第二种效果
’n 为总页数
function pagemode2(value1,value2)
dim out
val1 = value1
val4 = value2
for i = 1 to n
val2 = i
val3 = "第" & i & "页"
out = out & page_url(val1,val2,val3,val4) & " "
next
pagemode2 = out
end function
%>
使用举例(借用一下SunLine朋友的程序)
<%
sql="……………………"
rs.open sql,conn,1,1 ’连接表
rs.pagesize=10 ’这是每页显示几条记录10代表是10条
n = rs.pagecount ’取得总页数
page=page_request()&nb
更多信息请查看IT技术专栏