今天心情有點(diǎn)激動(dòng),想把"關(guān)于用DW ASP實(shí)現(xiàn)分頁(yè)技術(shù)的參考"分享給用DW ASP做網(wǎng)頁(yè)的朋友們.去掉只有"第一頁(yè),前一頁(yè),下一頁(yè),最后一頁(yè)"的小痛苦
此效果最后的顯示是:第N頁(yè)[共*頁(yè)] <<1 2 3 4 5 6 7 8 9 10 >>。
用DW ASP做網(wǎng)頁(yè)時(shí),在綁定記錄集后,代碼頁(yè)里馬上出現(xiàn)以下代碼:
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_數(shù)據(jù)庫(kù)名_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_數(shù)據(jù)庫(kù)名_STRING
Recordset1.Source = "SELECT * FROM 數(shù)據(jù)庫(kù)名"
Recordset1.CursorType = 1 ’將上面代碼的0改為1.
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0 ’再在此行的下一行開(kāi)始加入如下代碼:
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&"頁(yè)[共"&tPageCount&"頁(yè)]"
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:顯示的數(shù)字鏈接個(gè)數(shù)
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=StartPage To EndPage
If I=cPageNo Then
Response.Write "<b>"&I&"</b>"
Else
Response.Write "<a class=""pageNavi"" href=""?PageNo=" & I & """>" & I & "</a>"
End If
If I<>tPageCount Then Response.Write " "
Next
If EndPage<tPageCount Then
Response.Write " <a class=""pageNavi"" href=""?PageNo=" & (cPageNo NaviLength) & """>>></a>"
Else
Response.Write " <font color=""#CCCCCC"">>></font> "
End If
End Sub
%>
上面代碼中:RPP:指定每頁(yè)顯示的記錄條數(shù)。即每頁(yè)顯示幾條數(shù)據(jù)。
NaviLength:顯示的數(shù)字鏈接個(gè)數(shù),即10就為1 2 3 ...10的連接個(gè)數(shù)。
新聞熱點(diǎn)
疑難解答
圖片精選