您现在的位置:中国下载站学院中心网页设计Dreamweaver教程DreamWeaver基础教程 → 文章列表

用Dreamweaver和ASP实现分页技术的参考

作者:佚名  来源:不详  发布时间:2007-9-3 17:46:39   

减小字体 增大字体

 
 

  今天心情有点激动,想把"关于用DW+ASP实现分页技术的参考"分享给用DW+ASP做网页的朋友们.去掉只有"第一页,前一页,下一页,最后一页"的小痛苦

  此效果最后的显示是:第N页[共*页] <<1 2 3 4 5 6 7 8 9 10 >>。

  用DW+ASP做网页时,在绑定记录集后,代码页里马上出现以下代码:

<% 
Dim Recordset1 
Dim Recordset1_numRows 

Set Recordset1 = Server.CreateObject("ADODB.Recordset") 
Recordset1.ActiveConnection = MM_数据库名_STRING 
Recordset1.Source = "SELECT * FROM 表名" 
Recordset1.CursorType = 0 
Recordset1.CursorLocation = 2 
Recordset1.LockType = 1 
Recordset1.Open() 

Recordset1_numRows = 0 
%> 

  现在我们要来对代码做点修改,请在上面代码中修改为如下的代码:

<% 
Dim I 
Dim RPP 
Dim PageNo 
I=1 
RPP=50 
PageNo=CInt(Request("PageNo")) 
’上面即是新插入的, 
Dim Recordset1 
Dim Recordset1_numRows 
Set Recordset1 = Server.CreateObject("ADODB.Recordset") 
Recordset1.ActiveConnection = MM_数据库名_STRING 
Recordset1.Source = "SELECT * FROM 数据库名" 
Recordset1.CursorType = 1 ’将上面代码的0改为1. 
Recordset1.CursorLocation = 2 
Recordset1.LockType = 1 
Recordset1.Open() 
Recordset1_numRows = 0 ’再在此行的下一行开始加入如下代码: 
Recordset1.PageSize=RPP 
If PageNo<=0 Then PageNo=1 
If PageNo>Recordset1.PageCount Then PageNo=Recordset1.PageCount 
Recordset1.AbsolutePage=PageNo 
Sub ShowPageInfo(tPageCount,cPageNo) 
Response.Write "第"&cPageNo&"页[共"&tPageCount&"页]" 
End Sub 
Sub ShowPageNavi(tPageCount,cPageNo)  
If cPageNo<1 Then cPageNo=1 
If tPageCount<1 Then tPageCount=1 
If cPageNo>tPageCount Then cPageNo=tPageCount  
Dim NaviLength 
NaviLength=10 ’NaviLength:显示的数字链接个数  
Dim I,StartPage,EndPage  
StartPage=(cPageNo\NaviLength)*NaviLength+1 
If (cPageNo Mod NaviLength)=0 Then StartPage=StartPage-NaviLength  
EndPage=StartPage+NaviLength-1 
If EndPage>tPageCount Then EndPage=tPageCount  
If StartPage>1 Then 
Response.Write "<a class=""pageNavi"" href=""?PageNo=" & (cPageNo-NaviLength) & """><<</a> " 
Else 
Response.Write "<font color=""#CCCCCC""><<</font> " 
End If 
For I=StartPage To EndPage 
If I=cPageNo Then 
Response.Write "<b>"&I&"</b>" 
Else 
Response.Write "<a class=""pageNavi"" href=""?PageNo=" & I & """>" & I & "</a>" 
End If 
If I<>tPageCount Then Response.Write " " 
Next 
If EndPage<tPageCount Then 
Response.Write " <a class=""pageNavi"" href=""?PageNo=" & (cPageNo+NaviLength) & """>>></a>" 
Else 
Response.Write " <font color=""#CCCCCC"">>></font> " 
End If 
End Sub 
%> 

  上面代码中:RPP:指定每页显示的记录条数。即每页显示几条数据。

  NaviLength:显示的数字链接个数,即10就为1 2 3 ...10的连接个数。

  若要显示所有连接的页(个)数,你可以设置为:NaviLength=tPageCount。

  这时代码已经差不多了,但还要在显示的地方(如表格)中加点代码才行吧,(要不然怎么显示,呵~~~)如我们插入一个2行3列的表格。

  1.将光标移在第一行第一列中,切换到代码中加入:<%=(PageNo-1)*RPP+I%>

  这个代码是显示序号用的。

  2.右边2个单元格(当然你自己可以根据需要分更多的列)就是为你要显示的记录了。请分别从绑定的记录集中选中你要显示的字段拖放在相应的单元格中,(也可以选中后再点右下角的“插入”按钮)。这里我们就先拖2个进来如“编号”和“公司名称”。分别到1行第2个单元格和1行第3个单元格中。

  3.这个是个关键的,请将光标移到第一行任意单元格中,再来点选窗口底下的<tr>,这时你看看代码,<tr>....</tr>就被选中了。这时请在<tr>....</tr>的前面插入如下代码:

<% 
If Recordset1.EOF OR Recordset1.BOF Then 
Else 
For I=1 To RPP 
%>再在<tr>....</tr>之后插入如下代码: 
<% 
Recordset1.MoveNext 
If Recordset1.EOF OR Recordset1.BOF Then Exit For 
Next 
End If 
%> 

  4.这是就完成表格的第一行的工作。下来也是关键,即分页的连接。光标在第2行第一个单元格中时在代码窗口插入:

<% showPageInfo Recordset1.PageCount,PageNo %> 

  的代码。右边的2个单元格将其合并,在代码中插入:

<% showPageNavi Recordset1.PageCount,PageNo %> 

  的代码。

  5.大功告成!这时感快预览一下吧。。。。

  表格的全部代码如下:

<table width="710" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#333333"> 
<% 
If Recordset1.EOF OR Recordset1.BOF Then 
Else 
For I=1 To RPP 
%> 
<tr bgcolor="#FFFFFF"> 
<td width="30" align="center"><%=(PageNo-1)*RPP+I%></td> 
<td><%=(Recordset1.Fields.Item("编号").Value)%></td> 
<td><%=(Recordset1.Fields.Item("公司名称").Value)%></td> 
</tr> 
<% 
Recordset1.MoveNext 
If Recordset1.EOF OR Recordset1.BOF Then Exit For 
Next 
End If 
%> 
<tr bgcolor="#FFFFFF"> 
<td colspan="3"><table width="100%" border="0" cellspacing="0" cellpadding="2"> 
<tr bgcolor="#006699" class="w12"> 
<td width="121" align="center"><% showPageInfo Recordset1.PageCount,PageNo %> 
</td> 
<td width="573" align="center">  
<% showPageNavi Recordset1.PageCount,PageNo %> 
</td> 
</tr> 
</table></td> 
</tr> 
</table> 

  这时你去点应用程序中的“服务器行为”中的记录集,在代码中就显示为一下代码,也是我的原代码:

<% 
Dim I 
Dim RPP’RPP:指定每页显示的记录条数, 
Dim PageNo 
I=1 
RPP=50 
PageNo=CInt(Request("PageNo")) 
Dim Recordset1 
Dim Recordset1_numRows 
Set Recordset1 = Server.CreateObject("ADODB.Recordset") 
Recordset1.ActiveConnection = MM_数据库名_STRING 
Recordset1.Source = "SELECT * FROM 表名 ORDER BY 编号 ASC" 
Recordset1.CursorType = 1 
Recordset1.CursorLocation = 2 
Recordset1.LockType = 1 
Recordset1.Open() 

Recordset1_numRows = 0 
Recordset1.PageSize=RPP 
If PageNo<=0 Then PageNo=1 
If PageNo>Recordset1.PageCount Then PageNo=Recordset1.PageCount 
Recordset1.AbsolutePage=PageNo 

Sub ShowPageInfo(tPageCount,cPageNo) 
Response.Write "第"&cPageNo&"页[共"&tPageCount&"页]" 
End Sub 

Sub ShowPageNavi(tPageCount,cPageNo)  
If cPageNo<1 Then cPageNo=1 
If tPageCount<1 Then tPageCount=1 
If cPage

[1] [2]  下一页


在百度中搜索更多用Dreamweaver和ASP实现分页技术的参考相关网页 转贴于:中国下载站

  • 上一篇文章:如何用Dreamweaver批量做web网页
  • 下一篇文章:Dreamweaver制作网页的图片应用技巧
  • 阅读统计:[]
  • 中国下载站】【设为主页】【收藏本页】【打印本文】【回到顶部】【关闭此页

    相关文章
    文章评论(评论内容只代表网友观点,与本站立场无关!)

    用户名: 查看更多评论

    分 值:100分 85分 70分 55分 40分 25分 10分 0分

    内 容:

             (注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码


    设为首页 - 关于我们 - 广告服务 - 网站地图 - 加入收藏 - 网站声明 - 网站帮助 - 友情链接

    • Copyright (C) 2006-2008 www.cndownz.com All Rights Reserved.
      中国下载站 版权所有. 粤ICP备05141802号. 对本站有任何建议、意见或投诉,请来信:cndownzcom@yahoo.com.cn.
      喜欢中国下载站(cndownz.com),请把中国下载站(cndownz.com)告诉你QQ上的5位好友,多谢支持!