提供一款比较完整的asp教程分页函数,这款分页类可以实现上一页,下一页,等功能。
'仅供参考,你可以任意修改、传播;如果你对它进行了改良,希望你能给我一个
'副本,谢谢。
'--------------------------------------------------------------------
class turnpage
dim spageno,spagesize,spagecount,srecordcount,sabsoluterecord
private sub class_initialize()
spageno=trim(request.querystring("pageno"))
if spageno<>"" then
spageno = cdbl(spageno)
else
spageno = 1
end if
sabsoluterecord = 1
end subpublic sub getrs(byref conn,byref rs,byval sql,byval pagesize)
rs.open sql,conn,1,1
rs.pagesize = pagesize
spagesize = rs.pagesize
spagecount = rs.pagecount
srecordcount = rs.recordcount
if not rs.eof then rs.absolutepage = spageno
end sub
public function eof()
if sabsoluterecord<=spagesize then
'sabsoluterecord = sabsoluterecord + 1
eof = false
else
eof = true
end if
end function
public sub movenext()
sabsoluterecord = sabsoluterecord + 1
end sub
public sub getpagelist()
if spagecount<=1 then exit sub
dim surl,stmp,squery_string,p,n,i,a,b
surl = request.servervariables("url")
squery_string = request.servervariables("query_string")
stmp = split(surl,"/")
surl = stmp(ubound(stmp))
if squery_string <> "" then squery_string=replace(squery_string,"pageno=" & spageno,"")
if squery_string = "" then
surl = surl & "?"
else
surl = surl & "?" & squery_string & "&"
end if
surl = replace(surl,"&&","&")
p = spageno-1
n = spageno+1
if p<1 then p = 1
if n>spagecount then n = spagecount
a = spageno-5
b = spageno+5
if a<1 then a = 1
if b>spagecount then b = spagecount
response.write("<div class=""page_nav"">")
if spageno>1 then response.write("<a href=""" & surl & "pageno=1"">首页</a> <a href=""" & surl &"pageno=" & p & """>上页</a>")
for i=a to b
response.write(" <a href=""" & surl & "pageno=" & i & """")
if i = spageno then response.write(" style=""font-weight:bold; color:#ff0000;""")
response.write(">" & i & "</a>")
next
if spageno < spagecount then response.write(" <a href=""" & surl & "pageno=" & n & """>下页</a> <a href=""" & surl & "pageno=" & spagecount & """>末页</a>")response.write("</div>")
end sub
public sub getpagehtmllist(baseurl)
if spagecount<=1 then exit sub
dim p,n,i,a,b
p = spageno-1
n = spageno+1
if p<1 then p = 1
if n>spagecount then n = spagecount
a = spageno-5
b = spageno+5
if a<1 then a = 1
if b>spagecount then b = spagecount
response.write("<div class=""page_nav"">")
if spageno>1 then response.write("<a href=""" & baseurl & "_1.html"">首页</a> <a href=""" & baseurl & "_" & p & ".html"">上页</a>")
for i=a to b
response.write(" <a href=""" & baseurl & "_" & i & ".html""")
if i = spageno then response.write(" style=""font-weight:bold; color:#ff0000;""")
response.write(">" & i & "</a>")
next
if spageno < spagecount then response.write(" <a href=""" & baseurl & "_" & n & ".html"">下页</a> <a href=""" & baseurl & "_" & spagecount & ".html"">末页</a>")
response.write("</div>")
end sub
end class