今天心情有點激動,想把"關於用DW+ASP實現分頁技術的參考"分享給用DW+ASP做網頁的朋友們.去掉只有"第一頁,前一頁,下一頁,最後一頁"的小痛苦
此效果最後的顯示是:第N頁[共*頁] <<1 2 3 4 5 6 7 8 9 10 >>。
用DW+ASP做網頁時,在綁定記錄集後,代碼頁裡馬上出現以下代碼:
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_數據庫名_STRING
Recordset1.Source = "SELECT * FROM 表名"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<%
Dim I
Dim RPP
Dim PageNo
I=1
RPP=50
PageNo=CInt(Request("PageNo"))
’上面即是新插入的,
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_數據庫名_STRING
Recordset1.Source = "SELECT * FROM 數據庫名"
Recordset1.CursorType = 1 ’將上面代碼的0改為1.
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0 ’再在此行的下一行開始加入如下代碼:
Recordset1.PageSize=RPP
If PageNo<=0 Then PageNo=1
If PageNo>Recordset1.PageCount Then PageNo=Recordset1.PageCount
Recordset1.AbsolutePage=PageNo
Sub ShowPageInfo(tPageCount,cPageNo)
Response.Write "第"&cPageNo&"頁[共"&tPageCount&"頁]"
End Sub
Sub ShowPageNavi(tPageCount,cPageNo)
If cPageNo<1 Then cPageNo=1
If tPageCount<1 Then tPageCount=1
If cPageNo>tPageCount Then cPageNo=tPageCount
Dim NaviLength
NaviLength=10 ’NaviLength:顯示的數字鏈接個數
Dim I,StartPage,EndPage
StartPage=(cPageNo\NaviLength)*NaviLength+1
If (cPageNo Mod NaviLength)=0 Then StartPage=StartPage-NaviLength
EndPage=StartPage+NaviLength-1
If EndPage>tPageCount Then EndPage=tPageCount
If StartPage>1 Then
Response.Write "<a class=""pageNavi"" href=""?PageNo=" & (cPageNo-NaviLength) & """><<</a> "
Else
Response.Write "<font color=""#CCCCCC""><<</font> "
End If
For I=StartPag