• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 創建一個ASP通用分頁類(二)

    發表于:2007-07-14來源:作者:點擊數: 標簽:
    我們繼續接上期 在頁面里通過調用ShowPage()的方法顯示出來,ShowPage可以在GetRS以后的任意位置調用,也可以調用多次 Public Sub ShowPage() Dim str_tmp int_totalRecord=XD_RS.RecordCount If int_totalRecord=0 Then str_error=str_error "總記錄數為零

    我們繼續接上期

    在頁面里通過調用ShowPage()的方法顯示出來,ShowPage可以在GetRS以后的任意位置調用,也可以調用多次

    Public Sub ShowPage()
    Dim str_tmp
    int_totalRecord=XD_RS.RecordCount
    If int_totalRecord<=0 Then
      str_error=str_error & "總記錄數為零,請輸入數據"
      Call ShowError()
    End If
    If int_totalRecord="" Then
      int_TotalPage=1
    Else
      If int_totalRecord mod PageSize =0 Then
    int_TotalPage = CLng(int_TotalRecord / XD_PageSize * -1)*-1
      Else
    int_TotalPage = CLng(int_TotalRecord / XD_PageSize * -1)*-1+1
      End If
    End If

    If Int_curpage>int_Totalpage Then
      int_curpage=int_TotalPage
    End If

    '=====================================================
    '顯示分頁信息,各個模塊根據自己要求更改顯求位置
    '=====================================================
    response.write "
    str_tmp=ShowFirstPrv '顯示首頁、前一頁
    response.write str_tmp 
    str_tmp=showNumBtn '數字導航
    response.write str_tmp
    str_tmp=ShowNextLast  '下一頁、末頁
    response.write str_tmp
    str_tmp=ShowPageInfo
    response.write str_tmp
    response.write ""
    end Sub

    到這里類的功能才算完整(為了節省版面,我有些方法沒有放上去,再下面附上全部完整代碼)寫一個簡單頁面測試一下

    <% 
    ’把分頁類包含進來
    set conn = server.CreateObject("adodb.connection")
    conn.open "driver={microsoft aclearcase/" target="_blank" >ccess driver (*.mdb)};dbq=" & server.Mappath("pages.mdb")

    '#############類調用樣例#################
    '創建對象
    Set mypage=new xdownpage
    '得到數據庫連接
    mypage.getconn=conn
    'sql語句
    mypage.getsql="select * from [test] order by id asc"
    '設置每一頁的記錄條數據為5條
    mypage.pagesize=5
    '返回Recordset
    set rs=mypage.getrs()
    '顯示分頁信息,這個方法可以,在set rs=mypage.getrs()以后,可在任意位置調用,可以調用多次
    mypage.showpage()

    '顯示數據
    Response.Write("<br/>")
    for i=1 to mypage.pagesize
    '這里就可以自定義顯示方式了
        if not rs.eof then
            response.write rs(0) & "<br/>"
            rs.movenext
        else
             exit for
        end if
    next
    %>

    效果還不錯,該有的全有了。

    分頁過程中,還有一個比軟麻煩的問題是,在帶多個參數的URL中,如保證在頁面轉向的時候不掉失其它參數。我靠一個GetURL的過程來實現,并在生成導航時調用。

    Private Function GetURL()
      Dim strurl,str_url,i,j,search_str,result_url
      search_str="page="
      strurl=Request.ServerVariables("URL")
      Strurl=split(strurl,"/")
      i=UBound(strurl,1)
      str_url=strurl(i)'得到當前頁文件名
      str_params=Request.ServerVariables("QUERY_STRING")
      If str_params="" Then
      result_url=str_url & "?page="
      Else
      If InstrRev(str_params,search_str)=0 Then
    result_url=str_url & "?" & str_params &"&page="
      Else
    j=InstrRev(str_params,search_str)-2
    If j=-1 Then
      result_url=str_url & "?page="
    Else
      str_params=Left(str_params,j)
      result_url=str_url & "?" & str_params &"&page="
    End If
      End If
      End If
      GetURL=result_url
    End Function

    通過GetURL的處理,可以自動的獲取當前面的文件名,和所有帶的參數,實現了頁面轉換頁不丟失參數。
    三、后記
    通過這個分頁類,解決了每次分頁時需要重復寫的分頁部分代碼,方便了編程,也使的提高了主要代碼的可讀性。也希望能給大家在編程過程中帶來一點方便,由于本人水平有限,程序和文章中難免有錯,還望大家批評指正。

    全部代碼下載


    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>