How to compile paging functions?

Source: Internet
Author: User

Page. inc
<%
Sub ShowPageBar (TotalPage, CurPage, strUrl)
'ParametersTotalPage:All pages; CurPage:Current page number; StrUrl:The connection address used to flip the page.

DIM strPage
CurPage = GetValidPageNO (TotalPage, CurPage)
Response. Write "<table width ='' 100% ''>"
Response. Write "<tr> <td width ='' 100% ''align = ''right''>"
Response. Write"Page number:"& CurPage &"/"& TotalPage &""
IF InStr (strUrl ,"? ") = 0 THEN
StrPage = "? Page ="
ELSE
StrPage = "& Page ="
END IF

IF Curpage> 1 THEN
Response. Write "<a href =" & strUrl & strPage & "1>Page 1</A>"
ELSE
Response. Write"Page 1"
END IF

IF CurPage> = 2 THEN
Response. Write "<a href =" & strUrl & strPage & CurPage-1 & ">Previous Page</A>"
ELSE
Response. Write"Previous Page"
END IF

IF cInt (CurPage) <cInt (TotalPage) THEN
Response. Write "<a href =" & strUrl & strPage & CurPage + 1 & ">Next Page</A>"
ELSE
Response. Write"Next Page"
END IF

IF cInt (CurPage) <> cInt (TotalPage) THEN
Response. Write "<a href =" & strUrl & strPage & TotalPage & ">Last page</A>"
ELSE
Response. Write"Last page"
END IF
Response. Write "</td> </tr> </table>"
END SUB

Function GetValidPageNo (PageCount, CurPage)
Dim iPage
IPage = CurPage
IF cInt (CurPage) <1 THEN
IPage = 1
END IF
IF cInt (iPage)> cInt (PageCount) THEN
IPage = PageCount
END IF
GetValidPageNo = iPage
END Function
%>

Let's take a look at the example of referencing this function:

Chunfeng. asp
<! -- # Include Virtual = "page. inc" -->
<%
SET objConn = Server. CreateObject ("ADODB. CONNECTION ")
SET objRst = Server. CreateObject ("ADODB. RECORDSET ")
ObjConn. Open Application ("dsn ")

StrSQL = "select * fromQuery to use
ObjRst. Open strSQL, objConn, adOpenStatic
'Open Data Record.
ObjRst. PageSize = 20
'Set the number of data records on a single page
IPageCount = objRst. PageCount
'Defines a variable for the number of page numbers..
If Len (Request. QueryString ("Page") = 0 Then
CurPage = 1
Else
CurPage = CInt (Request. Querystring ("Page "))
End If
'Obtain the current page number..
ObjRst. AbsolutePage = CurPage
'Set the current page of the record set.

'Start to call the function that displays pages.,Display page number column.
'Function prototype: ShowPageBar (TotalPage, CurPage, strUrl ).
StrUrl = "chunfeng. asp"
'Define the connectionURL,You can use our own page address..
ShowPageBar iPageCount, CurPage, strUrl
'Call completed.

Bytes ----------------------------------------------------------------------------------------------------------------

Show your content here
Bytes ----------------------------------------------------------------------------------------------------------------

 

ObjConn. Close
SET objRst = NOTHING
SET objConn = NOTHING
%>

 

 

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.