I recently trained others on ASP paging. For novices who are new to ASP, the simplest paging is to use Recordset paging technology. It is mainly used for paging a small amount of data. It is the best for novices to learn. It is not suitable for paging a large amount of data. Recommended.
1. Create Recordset object
Copy the code as follows:Dim objMyRst
Set objMyRst=Server.CreateObject(ADODB.Recordset)
objMyRst.CursorLocation=adUseClientBatch 'The client can batch process
objMyRst.CursorType=adOpenStatic' The cursor type is a static type.
Note: Recordset objects cannot be used with Set objMyRst=Connection. .Excute The strSQL statement is created because the Recordset object it creates is adOpenFowardOnly and does not support record set paging
2. Open the Recordset object
and copy the code as follows:
Dim strSql
strSql=select * from ietable
objMyRst.Oepn strSql,ActiveConnection,,,adCmdText
3. Set the PageSize property of Recordset
and copy the code as follows:
objMyRst.PageSize=20.
The default PageSize is 10.
4. Set the AbsolutePage property of Recordset
as follows:
Copy the code as follows:
Dim intCurrentPage
intCurrentPage=1
objMyRst.AbsolutePage=intCurrentPage
AbsolutePage is 1 to the PageCount value of the Recordset object
5.
The codefor displaying data
copy code is as follows:
Response.Write(<table>)
PrintFieldName(objMyRst)
For i=1 To objMyRst.PageSize
PrintFieldValue(objMyRst)
objMyRst.MoveNext
If objMyRst.Eof Then Exit For
Next
Response.Write(</table> )
Description:
1. adOpenStatic, adUseCilentBatch, adCmdText are constants defined by adovbs.inc. To use them, copy adovbs.inc to the current directory and include them in the program.
Copy the code as follows:
<! --#Include File=adovbs.inc-->
2. The code of PrintFielName, PrintFieldValue function is as follows:
Copy the code as follows:
<%
Function PrintFieldName(objMyRst)
'The parameter objMyRst is a Recordset object
' Definition
Dim objFld
Response.Write < tr bgcolor='#CCCCCC'>
For Each objFld In objMyRst.Fields
Response.Write <td> & objFld.Name & </td>
Next
Response.Write(</tr>)
End Function
Function PrintFieldValue(objMyRst)
'The parameter objMyRst is a Recordset object
' Definition
Dim objFld
Response.Write(<tr >)
For Each objFld In objMyRst.Fields
'Response.Write<td> & objMyRst.Fields(intLoop).value & </td>
Response.Write <td> & objFld.value & </td>
Next
Response.Write(<tr>)
End Function
%>