您现在的位置:计算机技术学习网 > 技术中心 > WEB编程 > ASP >

dreamweaverMX通用分页代码研究

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 05:14 点击:
dreamweaverMX已经正式发布了,Deamweaver4 + Deamweaver ULTRADEV 4 的组合使他成为当然的制做网页的首选工具,(好象做广告:) )
好了,进入正题,
我在以前做网页的分页时候都是用自己写的服务端脚本(我从不用ADO的分页),用了MX后发现在这里面用分页太方便了,不过代码也有点太长了,大家看下面的代码就可以知道。用过之后我发现里面recordset 的cursortype设为0分页竟然可以正常工作!这令我吃惊不少,分析了代码之后才发现MX 是用了一种挺笨的方法实现的,效率很低,所以大家还是用1吧:)
分析如下:


<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="Connections/ncarcnn.asp" -->
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_ncarcnn_STRING
Recordset1.Source = "SELECT * FROM dbo.ncarinfo"

Recordset1.CursorType = 0
这里用0也可以正常运行,但是经过分析代码可以看出,用0的效率很低,建议用1


Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>


<%

以下为分页代码
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = 10
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<%
  *** Recordset状态, 定义状态变量

Dim Recordset1_total
Dim Recordset1_first
Dim Recordset1_last

set the record count
Recordset1_total = Recordset1.RecordCount

set the number of rows displayed on this page
If (Recordset1_numRows < 0) Then
  Recordset1_numRows = Recordset1_total
Elseif (Recordset1_numRows = 0) Then
  Recordset1_numRows = 1
End If

set the first and last displayed record
Recordset1_first = 1
Recordset1_last  = Recordset1_first + Recordset1_numRows - 1

if we have the correct record count, check the other stats 处理正确的rs
If (Recordset1_total <> -1) Then
  If (Recordset1_first > Recordset1_total) Then
    Recordset1_first = Recordset1_total
  End If
  If (Recordset1_last > Recordset1_total) Then
    Recordset1_last = Recordset1_total
  End If
  If (Recordset1_numRows > Recordset1_total) Then
    Recordset1_numRows = Recordset1_total
  End If
End If
%>
<%
*** Recordset Stats: if we dont know the record count, manually count them处理错误的RS

If (Recordset1_total = -1) Then

   count the total records by iterating through the recordset
  Recordset1_total=0
  While (Not Recordset1.EOF)
    Recordset1_total = Recordset1_total + 1
    Recordset1.MoveNext
  Wend

   reset the cursor to the beginning
  If (Recordset1.CursorType > 0) Then
    Recordset1.MoveFirst
  Else
    Recordset1.Requery
  End If

   set the number of rows displayed on this page
  If (Recordset1_numRows < 0 Or Recordset1_numRows > Recordset1_total) Then
    Recordset1_numRows = Recordset1_total
  End If

   set the first and last displayed record
  Recordset1_first = 1

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • WAP常见问题问答大全(四)
      • ASP开发必备:WEB打印代码大全
      • ASP调用系统ping命令
      • asp缓存技术
      • ASP教程:第三篇 ASP基础
      • 用ASP+XML打造留言本(4)
      • 关于ASP Recordset 分页出现负数解决方法及建议
      • 用asp怎样编写文档搜索页面(5)
      • ASP处理多关键词查询实例代码
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1