日期:2013-06-10  浏览次数:20747 次

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


假定我们的网站目录结构如下:

asp/            ' ASP 文件路径
images/            ' 图形文件路径
inc/            ' 包含文件路径
    content/        ' 存放诸如 header.inc、footer.inc 等每个页面都需要包含的文件
    control/        ' 存放诸如 navigator.inc、query.inc 等于分页控制有关的文件


额外的建议:
请将本页面的内容复制到 EditPlus 2.1 中,然后阅读(以后的文章均照此处理),您将会觉得阅读起来非常轻松,因为它的颜色配置非常舒服。当然我强烈推荐您也用 EditPlus 2.1 来编辑 .htm、.asp 、.inc 文件。



<一> 需要分页的 ASP 文件

sample.asp

<%
    ' 取得当前 ASP 页面的完整路径,重要技巧
    theScript    = Request.ServerVariables("SCRIPT_NAME")
    myconnstr    = "driver={SQL Server};server=yourserver;uid=sa;pwd=;database=mytest"
    thePageSize    = 20    ' 每页显示的记录数


    ' (1)构造 SQL 语句

    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>

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

                      <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                &n