日期:2013-05-14  浏览次数:21126 次

这个分页代码使用很简单,只有4个步骤:
(1)构造 SQL 查询语句、设置数据库连接字符串、设置每页记录显示数目
(2)插入分页控制代码 <b>navigator_init.inc</b> 文件
(3)在页面的适当地方(即你想显示“上页、下页”的地方),插入分页导航代码 <b>navigator.inc</b>
(4)用循环显示本页记录



<一> 需要分页的 ASP 文件

sample.asp

<%
    ' 取得当前 ASP 页面的完整路径,重要技巧
    theScript    = Request.ServerVariables("SCRIPT_NAME")

    ' (1)构造 SQL 语句

    myconnstr    = "driver={SQL Server};server=yourserver;uid=sa;pwd=;database=yourdatabase"
    thePageSize    = 20    ' 每页显示的记录数

    uSQL        = "select * from yourtablename "

    ' (2)插入分页控制代码
%>
<!--#include file="../inc/control/navigator_init.inc"-->

<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="../default.css" type="text/css">
</head>

                      <!-- 你的 HTML 代码//-->

                      <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td>
<!--(3)插入分页导航代码-->
<!--#include file="../inc/control/navigator.inc"-->
                          </td>
                        </tr>
                      </table>

                      <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td>
<!--(4)用循环显示本页记录-->

    <% For i = 1 To rs.pagesize %>
                      <!-- 你的记录显示代码//-->
    <%
        rs.MoveNext
        If rs.EOF Then
            Exit For
            rs.close
            conn.close
        End If
  &