Use the next article in the record in the database (ii)

Source: Internet
Author: User
Ii. use of bookmark (bookmark)

The bookmark (bookmark) makes a mark on a record of the recordset.

When used, move to that piece of data and give the Bookmark property a name, which is the name of the bookmark, and when you want to go back to that record, set the Bookmark property to the name of the bookmark mark you set.

Example of a bookmark

How do I use a bookmark (bookmark)? Let's look at an example of using a bookmark in an ASP code.

For example, ASP code rs13.asp as follows:

<%

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

Conn1. Open "dbq=" & Server.MapPath ("Ntopsamp.mdb") & ";D river={microsoft Access Driver (*.mdb)};D riverid=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") = "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>

&LT;TD align=center bgcolor= "#008080" ><font color= "#FFFFFF" > title </FONT></TD>

&LT;TD align=center bgcolor= "#008080" ><font color= "#FFFFFF" > Publishing </FONT></TD>

&LT;TD align=center bgcolor= "#008080" ><font color= "#FFFFFF" > Pictures </FONT></TD>

&LT;TD align=center bgcolor= "#008080" ><font color= "#FFFFFF" > Introduction </FONT></TD>

<TR>

&LT;TD bgcolor= "F7efde" align=center><%= rs2 ("title")%></td>

&LT;TD bgcolor= "F7efde" align=center><%= rs2 ("published")%></td>

&LT;TD bgcolor= "F7efde" align=center><%= rs2 ("picture")%></td>

&LT;TD bgcolor= "F7efde" align=center><%= rs2 ("Introduction")%></td>

</TR>

</TABLE>

<a href=rs13.asp?sel=first> First Article </A>

<% if session ("position") > 0 Then%>

<a href=rs13.asp?sel=prev> on a piece of </A>

<% End If%>

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

<a href=rs13.asp?sel=next> Next </A>

<% End If%>

<a href=rs13.asp?sel=last> last article </A>

<a href=rs13.asp?sel=set> Set bookmark</a>

<a href=rs13.asp?sel=go> to Bookmark</a>

<% rs2. Close%>

The bookmark (bookmark) Position of the user's recordset is stored by session ("BK"), and the bookmark is set by <a href=rs13.asp?sel=set> when the [set bookmark] Super connection is pressed. &LT;/A&GT, sets the SEL to set, and executes the rs13.asp ASP code again. From the following program part, first rs2. Move session ("position") returns to its last position and then uses session ("BK") = rs2. Bookmark is set, and session ("bookmark") stores the name of the bookmark mark:

If Request ("sel") = "Last" Then

Rs2. MoveLast

ElseIf Request ("sel") = "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

When the [to bookmark] Super connection is pressed, the <a href=rs13.asp?sel=go> to Bookmark</a&gt, the SEL is set to go, and the rs13.asp ASP code is executed again. By the above part of the program, by RS2. Bookmark = Session ("BK") returns to the location of the last bookmark mark.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.