最簡化分頁程式,附原始碼

來源:互聯網
上載者:User
程式|分頁|原始碼|分頁|原始碼 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 "第"&currentpage&"頁/共"&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="&currentpage-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="&currentpage+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="&currentpage-1&" class='01'>上一頁</a>]"
End If

'如果是最後一頁

If cint(currentpage)<cint(pagesum) Then
Response.Write "[<A HREF="&linkurl&"?Page="&currentpage+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



相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。