pagetest.asp 表现页面
<!--#include virtual="/conn.asp"-->
<!--#include virtual="/object.asp"-->
<%
strSql = "select * from authors"
set rs=server.CreateObject("ADODB.RecordSet")
rs.open strSql,conn,1,1
set page = new PageBase
page.pagesize = 3
if not isnumeric(request("page")) then
page.currentpage=1
else
if (cint(request("page")<1)) then
page.currentpage=1
else
page.currentpage=request("page")
end if
end if
page.linkurl="pagetest.asp"
page.show(rs)
page.FenYe(rs)
%>
object.asp 页对象
<%
'***********************************
'*
'* 尼德类
'*
'* 主要有:分页类。。。。。
'*
'* coolwind QQ :1294420
'*
'***********************************
class PageBase
dim pagesize '每页显示的记录数
dim currentpage'当然页面数
dim linkurl '链结URL
sub show(oRs)
'显示分页符号的子程序---------------------------------------------------------------
i=0
rs.Move pagesize*(currentpage-1)
do while not oRs.eof and i<pagesize
response.write oRs(1)&"<br>"
i=i+1
oRs.movenext
loop
End sub
'显示分页符号的子程序---------------------------------------------------------------
sub FenYe(oRs)
totalput = oRs.recordcount
pagesum = totalPut \ PageSize
'如果是第一页
response.write "第"¤tpage&"页/共"&pagesum&"页"
maxpage = 0
minpage = 0
if((currentpage-5)>1) then
minpage = currentpage-5
if (currentpage+4)>pagesum then
maxpage = pagesum
else
maxpage = currentpage+4
end if
else
minpage = 1
if pagesum>10 then
maxpage = 10
else
maxpage = pagesum
end if
end if
if(cint(currentpage-1)>0) then
if(cint(currentpage-1)>cint(pagesum)) then
response.write "<a href="&linkurl&"?Page="&pagesum&" ><<上一页</a>"
else
response.write "<a href="&linkurl&"?Page="¤tpage-1&" ><<上一页</a>"
end if
end if
for i=minpage to maxpage
if(cint(i)=cint(currentpage)) then
response.write "["&i&"]"
else
response.write "[<a href="&linkurl&"?Page="&i&" >"&i&"</a>]"
end if
next
if(cint(pagesum-currentpage)>0) then
response.write "<a href="&linkurl&"?Page="¤tpage+1&">下一页>></a>"
end if
response.write "<br>"
'以下是另一种分页显示界面
if currentpage=1 then
Response.Write " [最前页]"
Response.Write "[上一页]"
else
Response.Write "[<a href="&linkurl&"?page=1 class='01'>最前页</a>]"
Response.Write "[<a href="&linkurl&"?Page="¤tpage-1&" class='01'>上一页</a>]"
End If
'如果是最后一页
If cint(currentpage)<cint(pagesum) Then
Response.Write "[<A HREF="&linkurl&"?Page="¤tpage+1&" class='01'>下一页</a>]"
Response.Write "[<A HREF="&linkurl&"?Page="&pagesum&" class='01'>最末页</a>]"
else
Response.Write "[下一页]"
Response.Write "[最末页]"
End If
end sub
end class
%>
conn.asp 数据库链结
<%
'***********************************
'*
'*
'* 与MSSQL数据库连接
'*
'* coolwind QQ :1294420
'*
'***********************************
dim conn
dim connstr
connstr="provider=sqloledb;data source=servername;uid=sa;pwd=;database=pubs;"
set conn=server.createobject("ADODB.CONNECTION")
if err.number<>0 then
err.clear
set conn=nothing
response.write "数据库连接出错!"
Response.End
else
conn.open connstr
if err then
err.clear
set conn=nothing
response.write "数据库连接出错!"
Response.End
end if
end if
%>
大家看看,有什么看不懂的问我
本文地址:http://com.8s8s.com/it/it7692.htm