zoukankan      html  css  js  c++  java
  • ASP分页函数&&ASP分頁導航

        '//分页函数
        '//psize:每页显示的数据数
        '//pindex:当前页码
        '//tbName:表名
        '//keyIndex:根据什么字段分页,一般是自增长类型(access数据库的自动编号)
        '//where:查询条件
        '//order:排序条件,缺省为" order by " &keyIndex &" desc"
        '//总记录数与总页数可从返回的结果集中直接获取,字段datacount存储总记录数,字段pagecount存储总页数
        private pindex,datacount,pages
        
    'datacount = 0
        'pages = 1
        public function changePage(psize,tbName,keyIndex,where,order)
            
    dim sqlstring
            pindex 
    = Trim(Request.QueryString("page"))
            
    if not isnumeric(psize) or psize="" then psize=1'//每页显示的数据数
            if not isnumeric(pindex) or pindex="" then pindex=1'//当前页码
            if order="" then order=" order by " & keyIndex & " desc"
            
    '//获取总数据数
            'dim datacount,pages
            set rs=conn.execute("select count(*) as datacount from " & tbName & " where 1=1 " & where)
            datacount 
    = rs("datacount")'//总记录数
            rs.close
            
    set rs=nothing
            
    '//计算总页数
            if (datacount mod psize)=0 then
                pages
    =datacount \ psize
            
    else
                pages
    =datacount \ psize + 1
            
    end if
            
    '//
            if cint(pindex)>pages then pindex=pages
            
    '拼接sql字符串
            if pindex<=1 then
                sqlstring
    ="select top " & psize & " *," & datacount & " as datacount," & pages & " as pagecount from " &_
                            tbName 
    & " where 1=1 " & where & " " & order
            
    else
                sqlstring
    ="select top " & psize & " *," & datacount & " as datacount," & pages & " as pagecount from " &_
                            tbName 
    & " where 1=1 and " & keyIndex & " not in(select top " & (pindex-1)*psize & " " & keyIndex & " from " &_
                            tbName 
    & " where 1=1 " & where & " " & order & "" & where & " " & order
            
    end if
            
    'Response.Write(sqlstring)
            set changePage=conn.execute(sqlstring)
        
    end function
        
    '//分页导航
        '//fileName:文件名/当前页面的话,可以留空
        '//argString:分页参数例如classid=1&tid=16,分页必须的参数page不必填写
        '//pindex:当前页码
        '//datacount:总记录数
        '//pages:总页数
        '//showMsg:是否显示分页信息,参数为true/false
        '//showText:是否显示首页、上页、下页、末页的导航,参数为true/false
        '//showNumber:是否显示数字分页导航,参数为true/false
        'public function pageLink(fileName,argString,pindex,datacount,pages,showMsg,showText,showNumber)
        public function pageLink(fileName,argString,showMsg,showText,showNumber)
            
    '//
            if argString<>"" then argString = argString & "&"
            
    if not showText and not showNumber then showText=true
            
    '//
            if showMsg then
                Response.Write(
    "[")
                Response.Write(
    "第 <span style='color:red;'>" & pindex & "</span> 页")
                Response.Write(
    "/分 <span style='color:red;'>" & pages & "</span> 页")
                Response.Write(
    "/总 <span style='color:red;'>" & datacount & "</span> 条记录")
                Response.Write(
    "]&nbsp;")
            
    end if
            
    '//
            if showText then
                
    if pindex>1 then
                    Response.Write(
    "<a href='" & fileName & "?" & argString & "page=1'>[首页]</a>")
                    Response.Write(
    "&nbsp;")
                    Response.Write(
    "<a href='" & fileName & "?" & argString & "page=" & pindex - 1 & "'>[上页]</a>")
                
    else
                    Response.Write(
    "[首页]")
                    Response.Write(
    "&nbsp;")
                    Response.Write(
    "[上页]")
                
    end if
                Response.Write(
    "&nbsp;")
                
    if pindex<pages then
                    Response.Write(
    "<a href='" & fileName & "?" & argString & "page=" & pindex + 1 & "'>[下页]</a>")
                    Response.Write(
    "&nbsp;")
                    Response.Write(
    "<a href='" & fileName & "?" & argString & "page=" & pages & "'>[末页]</a>")
                
    else
                    Response.Write(
    "[下页]")
                    Response.Write(
    "&nbsp;")
                    Response.Write(
    "[末页]")
                
    end if
            
    end if
            
    '//
            if showNumber then
                Response.Write(
    "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")
                
    for i = 4 to 1 step -1
                    
    if (pindex - i)>0 then
                        Response.Write(
    "<a href='" & fileName & "?" & argString & "page=" & pindex - i & "'>" & pindex - i & "</a>")
                        Response.Write(
    "&nbsp;")
                    
    end if
                
    next
                
    '//
                Response.Write("<span style='color:red;'>" & pindex & "</span>")
                
    '//
                for i = 1 to 4
                    
    if (pindex + i)<=pages then
                        Response.Write(
    "&nbsp;")
                        Response.Write(
    "<a href='" & fileName & "?" & argString & "page=" & pindex + i & "'>" & pindex + i & "</a>")
                    
    end if
                
    next
                
    '//
            end if
            
    '//
        end function

    申明

    非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!

    博文欢迎转载,但请给出原文连接。

  • 相关阅读:
    经典算法之冒泡排序(Bubble Sort)-Python实现
    经典算法之快速排序(Quick Sort)-Python实现
    2020年SRE的随心感悟
    django: 像正常运行django的项目运行单个文件
    整理一下javascript中offsetWidth、clientWidth、width、scrollWidth、clientX、screenX、offsetX、pageX的具体含义
    requestAnimationFram 的优势及使用场景
    js 隐式数据转换带来的BUG
    为什么我不建议在js中使用链接变量分配
    关于JS函数传参的数据修改
    实现一个查看浏览器内核及版本号的功能函数
  • 原文地址:https://www.cnblogs.com/Athrun/p/1457727.html
Copyright © 2011-2022 走看看