萬盛學電腦網

 萬盛學電腦網 >> 網頁制作 >> dreamweaver教程 >> 用Dreamweaver和ASP實現分頁技術的參考

用Dreamweaver和ASP實現分頁技術的參考

  今天心情有點激動,想把"關於用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=(cPageNoNaviLength)*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 "<< "

  Else

  Response.Write "<< "

  End If

  For I=StartPage To EndPage

  If I=cPageNo Then

  Response.Write ""&I&""

  Else

  Response.Write "" & I & ""

  End If

  If I<>tPageCount Then Response.Write " "

  Next

  If EndPage

  Response.Write " >>"

  Else

  Response.Write " >> "

  End If

  End Sub

  %>

  上面代碼中:RPP:指定每頁顯示的記錄條數。即每頁顯示幾條數據。

  NaviLength:顯示的數字鏈接個數,即10就為1 2 3...10的連接個數。

  若要顯示所有連接的頁(個)數,你可以設置為:NaviLength=tPageCount。

copyright © 萬盛學電腦網 all rights reserved