Paging leaves, the current version is 0.04 Beta , is now seen wit tab fastest method, fast page turning by an average of only <= 32 msec, from the first page to the last page jump can be directly control in 200 ms
<% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "936"%>
<-! # The include File = "Cls_ShowoPage.asp" ->
<%
'================ =================================================
' Title: asp leaves paging class -ac exemplary call
'the name: ShowoPage (asp class)
' RCSfile: pageAC.asp
'Revision: 0.04Beta
' the Author: yezi (leaf)
'a Date: 2005-01-21 17:50:10
' Description: ASP page calls the class ac demonstration in support of Access / MSSQL / MySQL / pgSQL / the Oracle
'Business Card: QQ: 311 673, MSN: ishows @ msn.com, HTTP: //www.showo.com
' ====== ================================================== =========
'------------------------------------------------- ----------------------------------------------
the On Error Resume the Next
Startime the DIM, the endtime
'execution time statistics
Startime Timer = ()
' connected to the database
the DIM Db, Conn, Rs of
Db = "Provider = the Microsoft.Jet.OLEDB.4.0; the Data the Source =" & the Server.MapPath ( "db.mdb")
Conn = Server.CreateObject SET ( "ADODB.Connection")
conn.Open Db
'-------------------------------- -------------------------------------------------- -------------
%>
<HTML>
<head>
<title> ASP leaf exemplary call paging class -access </ title>
<Meta HTTP-equiv = "the type-the Content" Content = " text / HTML; charset = GB2312 ">
<Link the rel =" this stylesheet "href="page.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<Table width = "760" border = ". 1" cellspacing = "0" cellpadding = ". 4" align = left = "Center" borderColorDark = "# FFFFFF" bordercolorlight = "# CCCCCC">
<TR align = left = "Center">
<TD width = "60"> ID </ TD>
<TD width = "150"> title </ TD>
<TD width = "*"> content (before displaying 20 characters) </ TD>
<TD width = "150 "> time </ TD>
</ TR>
<%
Dim ORS
the Set new new Cls_ShowoPage ORS = 'Create Object
With ORS
.Conn = Conn' database connection object obtained
.DbType =" the AC "
'database type, AC to access, MSSQL is sqlserver2000, MSSQL_SP storage procedure Edition, MYSQL as mysql, PGSQL is PostgreSQL
.RecType = 0
'taking the total number of recording process (0 execution count,1 taken from the write sql statement, a fixed value of 2)
.RecSql = 0
'= 1 and = RecType if recording takes sql statement, if a = 2 value, equal = 0 ""
= 0 .RecTerm
' taken from the recording condition has changed or (0 no change, change 1, 2 is not set cookies timely statistics for search time)
.CookieName = "recac" 'If RecTerm = 2, cookiesname = "" , otherwise the write cookiesname
.Order 0 =' sorted (1 0 descending order), which pay attention to and below the main sql sort key ID corresponding
.PageSize = 30 'each page number of records
.JsUrl = "" 'of the path showo_page.js
.Sql = "id, aaaa, bbbb , cccc $ table1 $$$ id"' fields, tables, condition (no WHERE), sorting (no need ORDER BY), the primary key ID
End With
iRecCount=ors.RecCount()'记录总数
iRs=ors.ResultSet() '返回ResultSet
If iRecCount<1 Then%>
<tr bgcolor="">
<td >暂无记录</td>
</tr>
<%
Else
For i=0 To Ubound(iRs,2)
bgColor="#FFFFFF"
if i mod 2=0 then bgColor="#DFEFFF"
%>
<tr bgcolor="<%=bgColor%>">
<td width="60"><%=iRs(0,i)%></td>
<td width="150"><%=iRs(1,i)%></td>
<td width="*"><%=left(iRs(2,i),20)%></td>
<td width="150"><%=iRs(3,i)%></td>
</tr><%
Next
End If
%>
</table>
<table width="760" border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<td>
<%ors.ShowPage()%>
</td>
</tr>
</table>
<table width="760" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td align="center">
<%endtime=timer()%>
本页面执行时间:<%=FormatNumber((endtime-startime)*1000,3)%>毫秒</td>
</tr>
</table>
</body>
</html>
<%
iRs=NULL
ors=NULL
Set ors=NoThing
%>
<%
'=============================================== ==================
'name: asp leaves paging class
' the name: ShowoPage (asp class)
' RCSfile: Cls_ShowoPage.asp
'Revision: 0.04Beta
' the Author: yezi (leaf )
'a Date: 2005-01-21 17:50:10
' the Description: ASP pagination class support Access / MSSQL / MySQL / pgSQL / the Oracle
'Business Card: QQ: 311 673, MSN: ishows @ msn.com, HTTP: // www.showo.com
'============================================ =====================
Class Cls_ShowoPage
Private Showo_PageSize,Showo_CurrPage
Private Showo_Conn,Showo_DbType,Showo_RecType,Showo_RecSql,Showo_RecTerm,Showo_CookieName
Private S_Order,Showo_JsUrl
Private Showo_Sql,Showo_Field,Showo_Table,Showo_Where,Showo_OrderBy,Showo_Id
Private Showo_RecCount,Showo_PageCount,ResultSet_Sql
Private Showo_Cm,Showo_WhereOther,Showo_Order,Showo_Size,Showo_Mm 'MSSQL用
'================================================= ===============
'the Class_Initialize class initialization
' ============================= ===================================
Private Sub the Class_Initialize
Showo_PageSize = 10 'set the number of records per page the default value is 10
Showo_CurrPage = checkNum (Trim (the Request ( "Page")),. 1, -1) 'get the value of the current face
Showo_Order = ">"' default sort
Showo_Size = "MAX" 'default sort
Showo_WhereOther = ""' By default
End Sub
'================================================= ===============
'database connection object obtained Conn
' ============================ ====================================
Public Property Let Conn (ByVal objConn)
the Set Showo_Conn = objConn
End Property
'================================================= ===============
'database type to give the DbType
' ============================= ===================================
Public Property Let DbType (ByVal strDbType)
Showo_DbType = strDbType
End Property
'================================================= ===============
'taken RecType recording method Total (0 execution count, 1 sql statement taken from the writing, a fixed value of 2)
' ============ ================================================== ==
Public Property Let RecType (ByVal intRecType)
Showo_RecType = checkNum (intRecType, 0,2)
End Property
'=========================== =====================================
'RecSql' if taken RecType = 1 and = sql statement records If the value = 2 is equal to 0 = ""
'===================================== ===========================
Public Property Let RecSql (ByVal strRecSql)
Showo_RecSql = strRecSql
End Property
'================================================= ===============
'is RecTerm search conditions change (no change 0, 1 change)
' =================== =============================================
Public Property Let RecTerm ( intRecTerm ByVal)
Showo_RecTerm = the checkNum (intRecTerm, 0,2)
End Property
'================================================================
' CookieName 取得cookiename
'================================================================
Public Property Let CookieName(ByVal strCookieName)
Showo_CookieName=strCookieName
End Property
'================================================================
' Order 排序(0顺序,1降序)
'================================================================
Public Property Let Order(ByVal intOrder)
S_Order=CheckNum(intOrder,0,1)
If S_Order=1 Then
Showo_Order="<"
Showo_Size="MIN"
End If
End Property
'================================================= ===============
'the PageSize number of records is provided for each page, the default record 10
' ===================== ===========================================
Public Property Let the PageSize (ByVal intPageSize )
Showo_PageSize = checkNum (intPageSize, Showo_PageSize, -1)
End Property
'================================================= ===============
'JsUrl made showo_page.js path
' ========================== ======================================
Public Property Let JsUrl (ByVal strJsUrl)
Showo_JsUrl = strJsUrl
End Property
'================================================================
' Sql 取得sql所需表字段条件排序,输入:字段,表,条件,排序,主ID
'================================================================
Public Property Let Sql(ByVal str_sql)
Showo_Sql=Split(str_sql,"$")
Showo_Field=Showo_Sql(0)
Showo_Table=Showo_Sql(1)
Showo_Where=Showo_Sql(2)
Showo_OrderBy=Showo_Sql(3)
Showo_Id=Showo_Sql(4)
If Len(Showo_Where)>=3 Then
Showo_WhereOther=" And "&Showo_Where
Showo_Where=" Where "&Showo_Where
End If
If Len(Showo_OrderBy)>3 Then Showo_OrderBy=" ORDER BY "&Showo_OrderBy
End Property
'================================================================
' GetRecCount 取得记录总数
'================================================================
Private Function GetRecCount()
Select Case Showo_RecType
Case 1
GetRecCount=Showo_Conn.execute(Showo_RecSql,0,1)(0)
Case 2
GetRecCount=CheckNum(Showo_RecSql,0,-1)
Case Else
GetRecCount=Showo_Conn.execute("SELECT Count("&Showo_Id&") FROM "&Showo_Table&" "&Showo_Where,0,1)(0)
End Select
End Function
'================================================================
' RecCount 修正记录总数
'================================================================
Public Property Get RecCount()
RecCount=Request.Cookies("ShowoPage")(Showo_CookieName)
RecCount=CheckNum(RecCount,0,-1)
Select Case Showo_RecTerm
Case 1
RecCount=GetRecCount()
Response.Cookies("ShowoPage")(Showo_CookieName)=RecCount
Case 2
RecCount=GetRecCount()
Case Else
If RecCount=0 Then
RecCount=GetRecCount()
Response.Cookies("ShowoPage")(Showo_CookieName)=RecCount
End If
End Select
End Property
'================================================= ===============
'returns after the ResultSet record set tab
' ========================== ======================================
Public Property the ResultSet the Get ()
the ResultSet Null =
'Total number of records
= RecCount Showo_RecCount ()
'this page
the If Showo_RecCount> 0 the Then
' pages of
the If (Showo_RecCount Showo_PageSize MOD) = 0 the Then
Showo_PageCount = Showo_RecCount / Showo_PageSize
Else
Showo_PageCount = Showo_RecCount / Showo_PageSize +. 1
End the If
'this page
Showo_CurrPage = checkNum (Showo_CurrPage, 1 , Showo_PageCount)
the Select Case Showo_DbType
Case "AC" 'AC database
Set Showo_Rs=Server.CreateObject ("adodb.RecordSet")
ResultSet_Sql="SELECT "&Showo_Field&" FROM "&Showo_Table&" "&Showo_Where&" "&Showo_OrderBy
Showo_Rs.Open ResultSet_Sql,Showo_Conn,1,1,&H0001
Showo_Rs.AbsolutePosition=(Showo_CurrPage-1)*Showo_PageSize+1
Case "MSSQL" 'sqlserver2000数据库
If Showo_CurrPage=1 Then
ResultSet_Sql="SELECT TOP "&Showo_PageSize&" "&Showo_Field&" FROM "&Showo_Table&Showo_Where&" "&Showo_OrderBy
Else
ResultSet_Sql="SELECT "&Showo_Size&"("&Showo_Id&") FROM (SELECT TOP "&(Showo_CurrPage-1)*Showo_PageSize&" "&Showo_Id&" FROM "&Showo_Table&Showo_Where&" "&Showo_OrderBy&") AS tmpTable"
Showo_Mm=Showo_Conn.execute(ResultSet_Sql,0,1)(0)
ResultSet_Sql="SELECT TOP "&Showo_PageSize&" "&Showo_Field&" FROM "&Showo_Table&" WHERE "&Showo_Id&Showo_Order&Showo_Mm&Showo_WhereOther&" "&Showo_OrderBy
End If
Set Showo_Rs=Showo_Conn.execute(ResultSet_Sql)
Case "MSSQL_SP" 'sqlserver2000数据库存储过程版
Set Showo_Rs=server.CreateObject("Adodb.RecordSet")
Set Showo_Cm=Server.CreateObject("Adodb.Command")
Showo_Cm.CommandType=4
Showo_Cm.ActiveConnection=Showo_Conn
Showo_Cm.CommandText="SP_ShowoPage"
Showo_Cm.parameters(1)=Showo_CurrPage
Showo_Cm.parameters(2)=Showo_PageSize
Showo_Cm.parameters(3)=Showo_Field
Showo_Cm.parameters(4)=Showo_Table
Showo_Cm.parameters(5)=Showo_Where
Showo_Cm.parameters(6)=Showo_WhereOther
Showo_Cm.parameters(7)=Showo_OrderBy
Showo_Cm.parameters(8)=Showo_Id
Showo_Cm.parameters(9)=Showo_Size
Showo_Cm.parameters(10)=Showo_Order
Showo_Rs.CursorLocation=1
Showo_Rs.LockType=1
Showo_Rs.Open Showo_Cm
Case Else '其他情况按最原始的方法处理
Set Showo_Rs = Server.CreateObject ("adodb.RecordSet")
ResultSet_Sql="SELECT "&Showo_Field&" FROM "&Showo_Table&" "&Showo_Where&" "&Showo_OrderBy
Showo_Rs.Open ResultSet_Sql,Showo_Conn,1,1,&H0001
Showo_Rs.AbsolutePosition=(Showo_CurrPage-1)*Showo_PageSize+1
End Select
ResultSet=Showo_Rs.GetRows(Showo_PageSize)
Showo_Rs.close
Set Showo_Rs=Nothing
End If
End Property
'================================================= ===============
'input: check field, starting number (default number), the end of the numbers (-1 size is not checked)
' ========== ================================================== ====
Private Function checkNum (ByVal strstr, ByVal intStartNum, ByVal intEndNum)
checkNum = intStartNum
the If the IsNumeric (strstr) the Then checkNum = Clng (strstr)
the If intEndNum> -1Then
the If checkNum <checkNum = intStartNum intStartNum the Then
the If checkNum> the Then intEndNum = intEndNum the checkNum
End the If
End Function
'================================================================
' Class_Terminate 类注销
'================================================================
Private Sub Class_Terminate()
If IsObject(Showo_Conn) Then
Showo_Conn.Close
Set Showo_Conn=Nothing
End If
End Sub
'================================================================
' 上下页部分
'================================================================
Public Sub ShowPage()%>
<Script Language="JavaScript" type="text/JavaScript" src="<%=Showo_JsUrl%>showo_page.js"></Script>
<Script Language="JavaScript">
ShowoPage("<table style='BORDER-COLLAPSE: collapse' borderColor='#111111' height='10' cellSpacing='0' cellPadding='0' width='95%' border='0'><tr><td vAlign='bottom' style='font-family: Verdana,宋体; font-size: 11.5px; line-height: 15px'>","</td></tr></table>","页次:<font color='red'>","</font>/",""," "," 每页<font color='red'>","</font> "," 共计:<font color='red'>","</font></td><td vAlign='bottom' align='right' style='font-family: Verdana,宋体; font-size: 11.5px; line-height: 15px'>","<font face=webdings>9</font>","<font face=webdings>7</font>","<font face=webdings>8</font>","<font face=webdings>:</font>"," 跳转:","<font color='orange'>[","]</font>","","","<font color='red'>","</font>","","",<%=RecCount()%>,<%=Showo_PageSize%>,2)
</Script>
<%End Sub
End Class%>