zoukankan      html  css  js  c++  java
  • ASP分页代码

    <!--#include file="Conn.asp"-->
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>ASP分页程序</title>
    <link href="Style/default.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    <!--
    a:visited
    {
    color
    :#0000CC;
    text-decoration
    :none
    }
    a:hover,.red
    {
    color
    :#FF0000;
    }
    .sitelist td
    {
    font-size
    :12px;
    line-height
    :25px;
    }
    -->
    </style>
    </head>
    <body>
    <div class="searchbody">
     
    <table width="100%" border="0" cellspacing="1" cellpadding="0">
      
    <tr bgcolor="#EFEFEF" align="center">
       
    <td width="45%" height="25"><strong>ID</strong></td>
       
    <td><strong>名称</strong><strong>站长</strong><strong>详情 评论 报错 更多 收藏</strong></td>
      
    </tr>
      
    <tr bgcolor="#E7E3E7">
       
    <td height="1" colspan="2"></td>
      
    </tr>
     
    </table>
     
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="sitelist">
    <%
    Dim sqlStr,sqlStrCount,sqlOrder,sqlCondition,rsCount,strTableName,strIDName,strQuery,strBgColor
    Dim strPageName,intPageSize,intTotalNum,intTotalPage,intCurrentPage,i

    strPageName  
    = "Page.asp" '页面名称
    strTableName = "Table"  '表名
    strIDName  = "ID"   '主键名
    sqlCondition = ""   '查询条件
    strQuery  = ""   '分页URL条件字符串
    strBgColor  = Array("#FFFFFF""#E5ECF9")


    If sqlOrder  = "" Then sqlOrder = " ORDER BY "&strIDName&" DESC" '保证主表与子表排序一致

    If sqlCondition = "" Then
     sqlStrCount 
    = "SELECT COUNT("&strIDName&") AS TotalNum FROM "&strTableName
    Else
     sqlStrCount 
    = "SELECT COUNT("&strIDName&") AS TotalNum FROM "&strTableName&" WHERE "&sqlCondition
    End If
    Set rsCount = conn.Execute(sqlStrCount)

    intPageSize 
    = 20'每页显示的记录数
    intTotalNum = rsCount("TotalNum")

    If intTotalNum <> 0 Then

     intTotalPage 
    = Fix(intTotalNum / intPageSize)

     
    If intTotalNum Mod intPageSize > 0 Then intTotalPage = intTotalPage + 1
     intCurrentPage 
    = Request("intMePage")

     
    If intCurrentPage = "" Then
      intCurrentPage 
    = 1
     
    ElseIf Not IsNumeric(intCurrentPage) Then
      intCurrentPage 
    = 1
     
    Else
      intCurrentPage 
    = CInt(intCurrentPage)
     
    End If

     
    If intCurrentPage > intTotalPage Then
      intCurrentPage 
    = intTotalPage
     
    ElseIf intCurrentPage < 1 Then
      intCurrentPage 
    = 1
     
    End If

     
    If sqlCondition = "" Then
      sqlStr 
    = "SELECT TOP "&intPageSize&" * FROM "&strTableName&" WHERE ("&strIDName&" NOT IN(SELECT TOP "&(intPageSize * (intCurrentPage - 1))&" "&strIDName&" FROM "&strTableName&" "&sqlOrder&"))"&sqlOrder
     
    Else
      sqlStr 
    = "SELECT TOP "&intPageSize&" * FROM "&strTableName&" WHERE "&sqlCondition&" AND ("&strIDName&" NOT IN(SELECT TOP "&(intPageSize * (intCurrentPage - 1))&" "&strIDName&" FROM "&strTableName&" WHERE "&sqlCondition&sqlOrder&"))"&sqlOrder
     
    End If
     
    Set rs = conn.Execute(sqlStr)
     
     i 
    = 0
     
    While Not rs.EOF
    %>
      
    <tr bgcolor="<%=strBgColor(i mod 2)%>">
       
    <td width="47%" height="25"><%=rs(0)%></td>
       
    <td><%=rs(1)%></td>
      
    </tr>
      
    <%
      rs.MoveNext
      i 
    = i + 1
     
    Wend
     
    Call closeRs(rs)
    Else 
    %>
    <div align="center">没有查找到相关数据!</div>
    <%
    End If
    Call closeConn()
    %>
      
    <tr>
       
    <td colspan="2"><%Call Page()%></td>
      
    </tr>
     
    </table>
    </div>
    <%

    Sub Page()
    %>
    <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
     
    <form id="frmPage" name="frmPage" method="get" action="<%=strPageName%>?<%=strQuery%>">
      
    <tr>
       
    <td bgcolor="#FFFFFF"><span class="redbold"><%=intTotalNum%></span>条记录 页次<span class="redbold"><%=intCurrentPage%></span>/<span class="redbold"><%=intTotalPage%></span> 每页<span class="redbold"><%=intPageSize%></span>条 <href="<%Response.Write(strPageName&"?intMePage=1"&strQuery)%>">首页</a>
    <%
    If intCurrentPage > 1 Then 
    %>
        
    <href="<%Response.Write(strPageName&"?intMePage="&intCurrentPage - 1&strQuery)%>">上页</a>
    <%
    End If
    If intCurrentPage < intTotalPage Then 
    %>
        
    <href="<%Response.Write(strPageName&"?intMePage="&intCurrentPage + 1&strQuery)%>">下页</a>
    <%
    End If
    %>
        
    <href="<%Response.Write(strPageName&"?intMePage="&intTotalPage&strQuery)%>">尾页</a> 跳至
        
    <input class="pageform" name="intMePage" type="text" id="intMePage" size="2" />
        页
        
    <input class="pagego" name="btnGO" type="submit" id="btnGO" value="GO" />
       
    </td>
      
    </tr>
     
    </form>
    </table>
    <%
    End Sub
    %>
    </body>
    </html>

    申明

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

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

  • 相关阅读:
    【Javascript】javascript学习 二十二 JavaScript 对象简介
    【Javascript】javascript学习 二十六 JavaScript Boolean(逻辑)对象
    【Javascript】javascript学习 二十九 JavaScript HTML DOM 对象
    【Javascript】javascript学习 二十八 JavaScript RegExp 对象
    【Javascript】javascript学习 二十一 JavaScript 指导方针
    【Javascript】javascript学习 二十三 JavaScript 字符串(String)对象
    【Javascript】javascript学习 三十 JavaScript 浏览器检测
    【Javascript】javascript学习 二十五 JavaScript Array(数组)对象
    【Javascript】javascript学习 二十四 JavaScript Date(日期)对象
    【Javascript】javascript学习 二十七 JavaScript Math(算数)对象
  • 原文地址:https://www.cnblogs.com/Athrun/p/552551.html
Copyright © 2011-2022 走看看