函数型显示翻页连接

发表于:2007-06-30来源:作者:点击数: 标签:
这个程序将显示翻页连接功能单独抽出,而不涉及其它操作,可内置翻页效果,方便灵活。 pagehanshu.asp % ‘’设置页码及URL ‘’value1 翻页地址 ‘’value2 page的值 ‘’value3 地址标签 eg:第一页、下一页 ‘’value4 根据vaule1而定 ‘’如果 value1 = pa
这个程序将显示翻页连接功能单独抽出,而不涉及其它操作,可内置翻页效果,方便灵活。

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 = "<a href=" & value1 & val & "page=" & value2 & ">" & value3 & "</a>"
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 & "&nbsp;&nbsp;" & out2 & "&nbsp;&nbsp;" & out3 & "&nbsp;&nbsp;" & 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) & "&nbsp;&nbsp;"
next

pagemode2 = out
end function
%>



使用举例(借用一下SunLine朋友的程序)

<%

sql="……………………"
rs.open sql,conn,1,1 ‘’连接表
rs.pagesize=10 ‘’这是每页显示几条记录10代表是10条
n = rs.pagecount ‘’取得总页数

page=page_request() ‘’取得页码值
rs.AbsolutePage=page
%>


接下来将下面的代码放到需要的位置,用于显示翻页链接:
<%
out = pagemode1("page.asp",1)
‘’or
out = pagemode1("page.asp?id=1",0)
‘’or
out = pagemode2("page.asp",1)

response.write out
%>



呵呵,这个程序没有什么新东西,也没经过任何运算速度测试性能优化,纯粹是为了用起来方便,请大家多提意见,让我改进。

原文转自:http://www.ltesting.net