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
%>