WebComputing━ADO總結報告7

來源:互聯網
上載者:User
ado|web 執行個體一:分頁顯示及導航:
  為什麼我要再提分頁的這個問題呢?因為這是一個最基本的問題,雖然有很多關於分頁的文章,但我覺得他們的方法偏於複雜。其實RecordSet的AbsolutePage就可以輕鬆的實現分頁,當你指定了PageSize屬性後,對AbsolutePage指定值就可以翻轉到指定的頁面。但是如果你想使用AbsolutePage的話,你必須在開啟RecordSet對象之前將它的CursorLocation值設為adUseClient,這個屬性是繼承Connection對象的一個相同屬性的。你也可以在開啟Connection對象之前來設定它。下面是原始碼,為了方便,我將導覽列獨立成了一個子程式方便大家使用。
<%
sub navigator(PageNo,Target)
Response.Write "<table border=0>"
Response.Write "<tr>"
Response.Write "<td>"
if PageNo>1 then
Response.write "<a href="&chr(34)&Target&"?Page=1"&chr(34)&">┃第一頁</a>"
else
Response.Write "┃第一頁"
end if
Response.Write "</td>"
Response.Write "<td>"
if PageNo<rs.PageCount then
Response.write"<a href="&chr(34)&Target&"?Page="&PageNo+1&chr(34)&">┃下一頁</a>"
else
Response.Write "┃下一頁"
end if
Response.Write "</td>"
Response.Write "<td>"
if PageNo>1 then
Response.write "<a href="&chr(34)&Target&"?Page="&PageNo-1&chr(34)&">┃前一頁</a>"
else
Response.Write "┃前一頁"
end if
Response.Write "</td>"
Response.Write "<td>"
if PageNo<rs.PageCount then
Response.write "<a href="&chr(34)&Target&"?Page="&rs.PageCount&chr(34)&">┃最後一頁</a>"
else
Response.Write "┃最後一頁"
end if
Response.Write "</td>"
Response.Write "<td>"
Response.Write "┃頁次:"&PageNo&"/"&rs.PageCount&"頁┃"&rs.PageSize&"條記錄/頁┃"
Response.Write "</td>"
Response.Write "<td valign="middle">"
Response.Write "<form action="&chr(34)&Target&chr(34)&" method="&chr(34)&"POST"&chr(34)&">"
Response.Write "<input type="text"size=3 maxlength=4 name="Page">"
Response.Write " <input type="submit"value="轉到">"
Response.Write "</form>"
Response.Write "</td>"
Response.Write "</tr>"
Response.Write "</table>"
end sub
%>

<%
const adCmdText=&H0001
const adVarChar=200
const adInteger=3
const adParamInput=&H0001
const adCmdTable=&H0002
const adUseClient=3
const adDate=7
const adLongVarChar=201
set conn=Server.CreateObject("ADODB.Connection")
conn.ConnectionString="Driver={Microsoft Access Driver (*.mdb)};DBQ="& _
Server.Mappath("/source_asp")&"/process/process.mdb;"
conn.Open
%>

<%
const MaxPageSize=5
%>
<html>
<head>
<title> See Book </title>
</head>
<body>
<%
dim i,j,PageNo
set rs=Server.CreateObject("ADODB.RecordSet")
rs.ActiveConnection=conn
rs.CursorLocation=adUseClient
rs.Open "Select * From books",,,adCmdText
if rs.BOF then
Response.Write "歡迎使用圖書,資料管理程式!"
else
rs.PageSize=MaxPageSize
if isempty(Request.QueryString("Page")) then
PageNo=1
elseif cInt(Request.QueryString("Page"))<1 then
PageNo=1
elseif cInt(Request.QueryString("Page"))>rs.PageCount then
PageNo=rs.PageCount
else
PageNo=cInt(Request.QueryString("Page"))
end if
if Request.ServerVariables("Request_Method")="POST" and not Isempty(Request.Form("Page")) then
PageNo=cInt(Request.Form("Page"))
end if
rs.AbsolutePage=PageNo
Response.Write "<table border="0" width="100%">"
Response.Write "<tr><td colspan="&rs.fields.count&">"
Target="books.asp"
call navigator(PageNo,Target) "調用導覽列
Response.Write "</td></tr>"
Response.Write "<tr>"
for i=0 to rs.fields.count-1
Response.Write "<td>"&rs.fields.item(i).name&"</td>"
next
Response.Write "</tr>"
j=0
while (not rs.EO



相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

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 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。