An improved ASP public paging module

Source: Internet
Author: User
Tags rowcount
Paging with DWMX2004 plug-in package can implement various paging functions of ASP, but the code is a bit scary, we in the actual project development, there is no simpler way to achieve "once and for all"? The answer is yes.

The features we need:

1, call the module, only need to pass the recordset and the number of records displayed on each page;
2, you can click on the link to page, you can also directly enter the page number, return to the page;
3, do not consider the filename, the program every page can be in the current pages.

Specific writing content



You can turn the link into the page to make the picture button, so that the surface will be more beautiful.

Call Method:
1. Include the paging module file at the beginning of the program or where the page is to be used;
2, define variables: RowCount, the number of records displayed per page
3, call the page process: Callturnpage (recordset, ROWCOUNT)
4. Add "rowcount>0" condition to the condition of dowhile cyclic output recordset
5, at the end of the loop "loop before" plus: rowcount=rowcount-1


Use Example:

1.

2. We use DWMX2004 to create a new ASP page with the following contents

<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<!--#includefile = "connections/conn.asp"-->
<!--#includefile = "pagein.asp"--> ' introduction of public paging module
<% ' defines a recordset
Dimrsnews
Dimrsnews_numrows

Setrsnews=server.createobject ("ADODB.") Recordset ")
Rsnews. Activeconnection=mm_conn_string
Rsnews. Source= "Select*fromdbo.zoonewswherenisshow=1orderbynaddtimedesc"
Rsnews. Cursortype=1
Rsnews. cursorlocation=2
Rsnews. Locktype=1
Rsnews. Open ()

Rsnews_numrows=0
%>
<% ' Use repeat behavior (repeat <tr> label contents below)
Dimrepeat2__numrows
Dimrepeat2__index

Repeat2__numrows=20
Repeat2__index=0
Rsnews_numrows=rsnews_numrows+repeat2__numrows
%>

<tablewidth= "100%" border= "0" cellspacing= "0" cellpadding= "0" >
<tr>
<tdheight= "align=" "Right" >
<% ' key here, create a navigation bar on the duplicate content
Dimrowcount
Rowcount=20
Callturnpage (Rsnews,rowcount)
%>
</td>
</tr>
<tr>
<td>
<tablewidth= "border=" "0" align= "center" cellpadding= "0" cellspacing= "0" >
<tr>
<tdheight= "1" valign= "Top" class= "Dotx" ></td>
</tr>
<% ' repeat start
while ((repeat2__numrows<>0) and (notrsnews.eof))
%>
<tr>
<tdheight= "><%=" (rsnews. Fields.item ("Ntitle"). Value)%>
<inputtype= "Submit" name= "submit" value= "Submit" >
</td>
</tr>
<%
Repeat2__index=repeat2__index+1
Repeat2__numrows=repeat2__numrows-1
Rsnews. MoveNext ()
Wend ' Repeat end
%>
<tr>
<tdheight= "1" valign= "Top" class= "Dotx" ></td>
</tr>
</table></td>
</tr>
<tr>
<tdheight= "align=" "Right" >
<% ' Creates a navigation bar under the duplicate content, optional, note that there is no longer a need for dimrowcount
Rowcount=20
Callturnpage (Rsnews,rowcount)
%></td>
</tr>
</table>
</body>

<% ' Close the recordset
Rsnews. Close ()
Setrsnews=nothing
%>


PS: Programs are automatically filtered when users enter pages that do not exist (such as decimals, negative numbers, and so on).


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.