• <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-7-14 19:37 | 作者: 佚名    | 來源: 網絡轉載     | 查看: 11次 | 進入軟件測試論壇討論

    領測軟件測試網

    我們繼續接上期

    在頁面里通過調用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 access 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/


    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備10010545號-5
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品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>