Learning Reference: Implementing page pagination with dreamweaver+asp

Source: Internet
Author: User
Tags exit insert reference table name first row dreamweaver
dreamweaver| Reference | pagination | Web page

Today a little excited, want to "on the use of dw+asp to achieve the paging technology reference" to share with the dw+asp to do the Web page friends. Remove only "first page, previous page, next page, last page" of the little pain.
The final display of this effect is: Nth page [total * page] <<1 2 3 4 5 6 7 8 9 >>.

When you use dw+asp as a Web page, after you bind the recordset, the following code appears immediately in the code page:

<%
Dim Recordset1
Dim recordset1_numrows
Set Recordset1 = Server.CreateObject ("ADODB. Recordset ")
recordset1.activeconnection = mm_ database name _string
Recordset1.source = "SELECT * FROM table name"
Recordset1.cursortype = 0
Recordset1.cursorlocation = 2
Recordset1.locktype = 1
Recordset1.open ()
Recordset1_numrows = 0
%>
Now we're going to make some changes to the code, please change it to the following code in the code:

<%
Dim I
Dim RPP
Dim PageNo
I=1
Rpp=50
Pageno=cint (Request ("PageNo"))
' That's the new insertion,
Dim Recordset1
Dim recordset1_numrows
Set Recordset1 = Server.CreateObject ("ADODB. Recordset ")
recordset1.activeconnection = mm_ database name _string
Recordset1.source = "SELECT * From Database name"
Recordset1.cursortype = 1 ' Change 0 of the above code to 1.
Recordset1.cursorlocation = 2
Recordset1.locktype = 1
Recordset1.open ()
recordset1_numrows = 0 ' again on the next line of this row, start adding the following code:
Recordset1.pagesize=rpp
If pageno<=0 Then pageno=1
If Pageno>recordset1.pagecount Then Pageno=recordset1.pagecount
Recordset1.absolutepage=pageno
Sub Showpageinfo (Tpagecount,cpageno)
Response.Write "&cPageNo&" page [Total &tPageCount& page]
End Sub
Sub Showpagenavi (Tpagecount,cpageno)
If cpageno<1 Then cpageno=1
If tpagecount<1 Then tpagecount=1
If Cpageno>tpagecount Then Cpageno=tpagecount
Dim Navilength
navilength=10 ' navilength: Number of digital links displayed
Dim I,startpage,endpage
Startpage= (cpageno\navilength) *navilength+1
If (Cpageno Mod navilength) =0 Then startpage=startpage-navilength
Endpage=startpage+navilength-1
If Endpage>tpagecount Then Endpage=tpagecount
If startpage>1 Then
Response.Write "<a class=" "Pagenavi" "href=" "? Pageno= "& (cpageno-navilength) &" "><<</a>"
Else
Response.Write "<font color=" "#CCCCCC" "><<</font>"
End If
For I=startpage to EndPage
If I=cpageno Then
Response.Write "<b>" &I& "</b>"
Else
Response.Write "<a class=" "Pagenavi" "href=" "? Pageno= "& I &" ">" & I & "</a>"
End If
If i<>tpagecount Then Response.Write ""
Next
If Endpage<tpagecount Then
Response.Write "<a class=" "Pagenavi" "href=" "? Pageno= "& (cpageno+navilength) &" ">>></a>"
Else
Response.Write "<font color=" "#CCCCCC" ">>></font>"
End If
End Sub
%> The above code: RPP: Specifies the number of record bars to display per page. That is, each page displays several data.

Navilength: The number of digital links displayed, that is, 10 to 1 2 3 ... 10 of the number of connections.

To display all connected pages (number), you can set it to: Navilength=tpagecount.

At this point the code is almost, but also in the display of places (such as tables) add some code to do it, (otherwise how to show, ah ~ ~ ~) If we insert a 2 rows of 3 columns of the table.

1. Move the cursor to the first column of the first row, and switch to code to add: <%= (PageNo-1) *rpp+i%>

This code is used to display serial numbers.

2. The 2 cells on the right (of course you can have more columns depending on your needs) are the records you want to display. Select the fields you want to display from the bound Recordset, respectively, in the corresponding cell (or select the Insert button in the lower-right corner of the point). We're going to drag 2 of them in here. such as "number" and "Company name." to 1 lines, cell 2nd, and cell 3rd in line 1.

3. This is a key, please move the cursor to the first row of any cell, and then click the <tr> under the window, then you look at the code,<tr>....</tr> is selected. At this point, insert the following code in front of <tr>....</tr>:
<%
If recordset1.eof OR Recordset1.bof Then
Else
For I=1 to RPP
%> then insert the following code after <tr>....</tr>:
<%
Recordset1.movenext
If recordset1.eof OR recordset1.bof Then Exit for
Next
End If
%>

4. This is the first line of work on completing the form. Down is also the key, that is, pagination of the connection. The cursor is inserted in the Code window at the first cell in line 2nd:

<% showpageinfo Recordset1.pagecount,pageno%> code. The 2 cells on the right merge them and insert them in your code:

<% Showpagenavi Recordset1.pagecount,pageno%> code.

5. It's done! The sense of a quick preview ....

The full code for the table is as follows:

<table width= "710" border= "0" align= "center" cellpadding= "3" cellspacing= "1" bgcolor= "#333333" >
<%
If recordset1.eof OR Recordset1.bof Then
Else
For I=1 to RPP
%>
<tr bgcolor= "#FFFFFF" >
&LT;TD width= align= "center" ><%= (PageNo-1) *rpp+i%></td>
<td><%= (Recordset1.Fields.Item ("number"). Value)%></td>
<td><%= (Recordset1.Fields.Item ("Company name"). Value)%></td>
</tr>
<%
Recordset1.movenext
If recordset1.eof OR recordset1.bof Then Exit for
Next
End If
%>
<tr bgcolor= "#FFFFFF" >
&LT;TD colspan= "3" ><table width= "100%" border= "0" cellspacing= "0" cellpadding= "2" >
<tr bgcolor= "#006699" class= "W12" >
&LT;TD width= "121" align= "center" ><% Showpageinfo Recordset1.pagecount,pageno%>
</td>
&LT;TD width= "573" align= "center" >
<% Showpagenavi Recordset1.pagecount,pageno%>
</td>
</tr>
</table></td>
</tr>
</table>
Then you go to the recordset in the "Server Behavior" in the application, which is shown in the code as code and my original code:

<%
Dim I
Dim RPP ' RPP: Specifies the number of record bars to display per page,
Dim PageNo
I=1
Rpp=50
Pageno=cint (Request ("PageNo"))
Dim Recordset1
Dim recordset1_numrows
Set Recordset1 = Server.CreateObject ("ADODB. Recordset ")
recordset1.activeconnection = mm_ database name _string
Recordset1.source = "SELECT * from table name ORDER by number ASC"
Recordset1.cursortype = 1
Recordset1.cursorlocation = 2
Recordset1.locktype = 1
Recordset1.open ()
Recordset1_numrows = 0
Recordset1.pagesize=rpp
If pageno<=0 Then pageno=1
If Pageno>recordset1.pagecount Then Pageno=recordset1.pagecount
Recordset1.absolutepage=pageno
Sub Showpageinfo (Tpagecount,cpageno)
Response.Write "&cPageNo&" page [Total &tPageCount& page]
End Sub
Sub Showpagenavi (Tpagecount,cpageno)
If cpageno<1 Then cpageno=1
If tpagecount<1 Then tpagecount=1
If Cpageno>tpagecount Then Cpageno=tpagecount
Dim Navilength
Navilength=20 ' navilength: Number of digital links displayed
Dim I,startpage,endpage
Startpage= (cpageno\navilength) *navilength+1
If (Cpageno Mod navilength) =0 Then startpage=startpage-navilength
Endpage=startpage+navilength-1
If Endpage>tpagecount Then Endpage=tpagecount
If startpage>1 Then
Response.Write "<a class=" "Pagenavi" "href=" "? Pageno= "& (cpageno-navilength) &" "><<</a>"
Else
Response.Write "<font color=" "#CCCCCC" "><<</font>"
End If
For I=startpage to EndPage
If I=cpageno Then
Response.Write "<b>" &I& "</b>"
Else
Response.Write "<a class=" "Pagenavi" "href=" "? Pageno= "& I &" ">" & I & "</a>"
End If
If i<>tpagecount Then Response.Write ""
Next
If Endpage<tpagecount Then
Response.Write "<a class=" "Pagenavi" "href=" "? Pageno= "& (cpageno+navilength) &" ">>></a>"
Else
Response.Write "<font color=" "#CCCCCC" ">>></font>"
End If
End Sub
%> But there is a disadvantage is: if you want to find 99 page time >>9 times, if there is an input box, enter 99 after the return to 99 on the perfect. I do not know how to modify in the dw+asp can be achieved? Expect.

Related Article

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.