用Dreamweaver和ASP實現(xiàn)分頁技術的參考_Dreamweaver教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!

        今天心情有點激動,想把"關于用DW ASP實現(xiàn)分頁技術的參考"分享給用DW ASP做網(wǎng)頁的朋友們.去掉只有"第一頁,前一頁,下一頁,最后一頁"的小痛苦

        此效果最后的顯示是:第N頁[共*頁] <<1 2 3 4 5 6 7 8 9 10 >>。

        用DW ASP做網(wǎng)頁時,在綁定記錄集后,代碼頁里馬上出現(xiàn)以下代碼:

      <%
      Dim Recordset1
      Dim Recordset1_numRows

      Set Recordset1 = Server.CreateObject("ADODB.Recordset")
      Recordset1.ActiveConnection = MM_數(shù)據(jù)庫名_STRING
      Recordset1.Source = "SELECT * FROM 表名"
      Recordset1.CursorType = 0
      Recordset1.CursorLocation = 2
      Recordset1.LockType = 1
      Recordset1.Open()

      Recordset1_numRows = 0
      %>

        現(xiàn)在我們要來對代碼做點修改,請在上面代碼中修改為如下的代碼:

      <%
      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ù)庫名_STRING
      Recordset1.Source = "SELECT * FROM 數(shù)據(jù)庫名"
      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:顯示的數(shù)字鏈接個數(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 "&nbsp;"
      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:指定每頁顯示的記錄條數(shù)。即每頁顯示幾條數(shù)據(jù)。

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

      共3頁上一頁123下一頁
      /所屬分類:Dreamweaver教程/更新時間:2007-03-29
      相關Dreamweaver教程