位置:首頁 > 軟件下載 > UI設計

對數(shù)據庫中的記錄用上一條下一條顯示(2)

2022-06-12發(fā)布者:ylm大?。?/span> 下載:0

文件大小:

軟件介紹

二、用Bookmark(書簽)

Bookmark(書簽)對RecordSet的一條記錄做一個記號。

使用時先移動到那條資料,然后給予Bookmark屬性一個名稱,即書簽記號的名稱,當要回到該條記錄時,將Bookmark 屬性設為所設定書簽記號的名稱即可。

Bookmark例子

如何使用Bookmark(書簽)呢?讓我們看一個於asp程式碼當中使用Bookmark的例子。

譬如ASP程式碼rs13.asp如下:

<%

Set conn1 = Server.CreateObject("ADODB.Connection")

conn1.Open "DBQ="& Server.MapPath("ntopsamp.mdb") &";Driver={Microsoft access Driver (*.mdb)};DriverId=25;FIL=MS Access;"

Set rs2 = Server.CreateObject("ADODB.Recordset")

SqlStr = "SELECT * From 著作"

rs2.Open SqlStr,conn1,1,1

rs2.MoveNext

if Request("sel") = "last" then

rs2.MoveLast

elseif Request("sel") = "first" then

rs2.MoveFirst

elseif Request("sel") = "PRev" then

session("position") = Session("position") - 1

rs2.Move Session("position")

elseif Request("sel") = "next" then

Session("position") = Session("position") + 1

rs2.Move Session("position")

elseif Request("sel") = "set" then

rs2.Move Session("position")

Session("bk") = rs2.Bookmark

elseif Request("sel") = "go" then

rs2.Bookmark = Session("bk")

else

Session("position") = 0

end if

%>

<TABLE COLSPAN=8 CELLPADDING=5 BORDER=0>

<TR>

<TD ALIGN=CENTER BGCOLOR="#008080"><FONT COLOR="#FFFFFF">書名</FONT></TD>

<TD ALIGN=CENTER BGCOLOR="#008080"><FONT COLOR="#FFFFFF">出版</FONT></TD>

<TD ALIGN=CENTER BGCOLOR="#008080"><FONT COLOR="#FFFFFF">圖片</FONT></TD>

<TD ALIGN=CENTER BGCOLOR="#008080"><FONT COLOR="#FFFFFF">簡介</FONT></TD>

<TR>

<TD BGCOLOR="f7efde" ALIGN=CENTER><%= rs2("書名")%></TD>

<TD BGCOLOR="f7efde" ALIGN=CENTER><%= rs2("出版")%></TD>

<TD BGCOLOR="f7efde" ALIGN=CENTER><%= rs2("圖片")%></TD>

<TD BGCOLOR="f7efde" ALIGN=CENTER><%= rs2("簡介")%></TD>

</TR>

</TABLE>

<A href=rs13.asp?sel=first>第一條</A>

<% if Session("position") > 0 then %>

<A href=rs13.asp?sel=prev>上一條</A>

<% end if %>

<% if Session("position") < rs2.RecordCount -1 then %>

<A href=rs13.asp?sel=next>下一條</A>

<% end if %>

<A href=rs13.asp?sel=last>最末條</A>

<A href=rs13.asp?sel=set>設定Bookmark</A>

<A href=rs13.asp?sel=go>到Bookmark</A>

<% rs2.Close %>

由Session("bk")儲存這個使用者RecordSet 的bookmark(書簽)位置,當按下 [設定Bookmark] 超級連接時,由<A href=rs13.asp?sel=set>設定Bookmark</A>,將sel設定為set,并重新執(zhí)行rs13.asp的asp碼。由以下的程式部份,首先rs2.Move Session("position")回到上次的位置,然后使用Session("bk") = rs2.Bookmark設定書簽,Session("Bookmark")儲存書簽記號的名稱:

if Request("sel") = "last" then

rs2.MoveLast

elseif Request("sel") = "first" then

rs2.MoveFirst

elseif Request("sel") = "prev" then

Session("position") = Session("position") - 1

rs2.Move Session("position")

elseif Request("sel") = "next" then

Session("position") = Session("position") + 1

rs2.Move Session("position")

elseif Request("sel") = "set" then

rs2.Move Session("position")

Session("bk") = rs2.Bookmark

elseif Request("sel") = "go" then

rs2.Bookmark = Session("bk")

else

Session("position") = 0

end if

當按下 [到Bookmark] 超級連接時,由<A href=rs13.asp?sel=go>到Bookmark</A>,將sel設定為go,并重新執(zhí)行rs13.asp的asp碼。由以上的程式部份,由rs2.Bookmark = Session("bk")回到上次書簽記號的位置。 

發(fā)表評論(共0條評論)
請自覺遵守互聯(lián)網相關政策法規(guī),評論內容只代表網友觀點,發(fā)表審核后顯示!

版權聲明:

1 本站所有資源(含游戲)均是軟件作者、開發(fā)商投稿,任何涉及商業(yè)盈利目的均不得使用,否則產生的一切后果將由您自己承擔!

2 本站將不對任何資源負法律責任,所有資源請在下載后24小時內刪除。

3 若有關在線投稿、無法下載等問題,請與本站客服人員聯(lián)系。

4 如侵犯了您的版權、商標等,請立刻聯(lián)系我們并具體說明情況后,本站將盡快處理刪除,聯(lián)系QQ:2499894784

返回頂部