当前位置: 首页 > 图文教程 > 网络编程 > ASP > 分页代码

ASP
利用ASP输出excel文件一例
asp中使用js的encodeURIComponent
ASP动态网站制作中使用MYSQL的分析
如何编写通用的ASP防SQL注入攻击程序
ASP脚本变量、函数、过程和条件语句
ASP内建对象Application和Session
ASP基础教程:常用的 ASP ActiveX 组件
ASP程序漏洞解析及黑客入侵防范方法
ASP访问带多个参数的存储过程
用ASP和SQL语句动态的创建Access表
ASP初学者学习ASP指令
ASP开发中有用的函数(function)集合(1)
ASP开发中有用的函数(function)集合(2)
ASP开发中有用的函数(function)集合(3)
ASP网站程序自动升级实现的方法
ASP开发中的(VBScript)类基础学习
ASP代码:防止重复多次提交表单的方法
在ASP中使用类,实现模块化
ASP基础教程之学习ASP中子程序的应用
ASP技巧:ASP中三个常用语句的使用技巧

ASP 中的 分页代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 34 ::
收藏到网摘: n/a

分页代码:
<%''本程序文件名为:Pages.asp%>
<%''包含ADO常量表文件adovbs.inc,可从"\Program Files\Common Files\System\ADO"目录下拷贝%>
<!--#Include File="adovbs.inc"-->
<%''*建立数据库连接,这里是Oracle8.05数据库 Set conn=Server.CreateObject("ADODB.Connection") conn.Open "Provider=msdaora.1;Data Source=YourSrcName;User ID=YourUserID;Password=YourPassword;" Set rs=Server.CreateObject("ADODB.Recordset") ''创建Recordset对象 rs.CursorLocation=adUseClient ''设定记录集指针属性 ''*设定一页内的记录总数,可根据需要进行调整 rs.PageSize=10 ''*设置查询语句 StrSQL="Select ID,姓名,住址,电话 from 通讯录 Order By ID" rs.Open StrSQL,conn,adOpenStatic,adLockReadOnly,adCmdText
%>
<HTML>
<HEAD>
<title>分页示例</title>
<script language=javascript> //点击"[第一页]"时响应: function PageFirst() { document.MyForm.CurrentPage.selectedIndex=0; document.MyForm.CurrentPage.onchange(); } //点击"[上一页]"时响应: function PagePrior() { document.MyForm.CurrentPage.selectedIndex--; document.MyForm.CurrentPage.onchange(); } //点击"[下一页]"时响应: function PageNext() { document.MyForm.CurrentPage.selectedIndex++; document.MyForm.CurrentPage.onchange(); } //点击"[最后一页]"时响应: function PageLast() { document.MyForm.CurrentPage.selectedIndex=document.MyForm.CurrentPage.length-1; document.MyForm.CurrentPage.onchange(); } //选择"第?页"时响应: function PageCurrent() { //Pages.asp是本程序的文件名 document.MyForm.action='Pages.asp?Page='+(document.MyForm.CurrentPage.selectedIndex+1) document.MyForm.submit(); }
</Script>
</HEAD>
<BODY bgcolor="#ffffcc" link="#008000" vlink="#008000" alink="#FF0000"">
<%IF rs.Eof THEN Response.Write("<font size=2 color=#000080>[数据库中没有记录!]</font>") ELSE ''指定当前页码 If Request("CurrentPage")="" Then rs.AbsolutePage=1 Else rs.AbsolutePage=CLng(Request("CurrentPage")) End If ''创建表单MyForm,方法为Get Response.Write("<form method=Get name=MyForm>") Response.Write("<p align=center><font size=2 color=#008000>") ''设置翻页超链接 if rs.PageCount=1 then Response.Write("[第一页] [上一页] [下一页] [最后一页] ") else if rs.AbsolutePage=1 then Response.Write("[第一页] [上一页] ") Response.Write("[<a href=javascript:PageNext()>下一页</a>] ") Response.Write("[<a href=javascript:PageLast()>最后一页</a>] ") else if rs.AbsolutePage=rs.PageCount then Response.Write("[<a href=javascript:PageFirst()>第一页</a>] ") Response.Write("[<a href=javascript:PagePrior()>上一页</a>] ") Response.Write("[下一页] [最后一页] ") else Response.Write("[<a href=javascript:PageFirst()>第一页</a>] ") Response.Write("[<a href=javascript:PagePrior()>上一页</a>] ") Response.Write("[<a href=javascript:PageNext()>下一页</a>] ") Response.Write("[<a href=javascript:PageLast()>最后一页</a>] ") end if end if end if ''创建下拉列表框,用于选择浏览页码 Response.Write("第<select size=1 name=CurrentPage onchange=PageCurrent()>") For i=1 to rs.PageCount if rs.AbsolutePage=i then Response.Write("<option selected>"&i&"</option>") ''当前页码 else Response.Write("<option>"&i&"</option>") end if Next Response.Write("</select>页/共"&rs.PageCount&"页 共"&rs.RecordCount&"条记录</font><p>") Response.Write("</form>") ''创建表格,用于显示 Response.Write("<table align=center cellspacing=1 cellpadding=1 border=1") Response.Write(" bordercolor=#99CCFF bordercolordark=#b0e0e6 bordercolorlight=#000066>") Response.Write("<tr bgcolor=#ccccff bordercolor=#000066>") Set Columns=rs.Fields ''显示表头 For i=0 to Columns.Count-1 Response.Write("<td align=center width=200 height=13>") Response.Write("<font size=2><b>"&Columns(i).name&"</b></font></td>") Next Response.Write("</tr>") ''显示内容 For i=1 to rs.PageSize Response.Write("<tr bgcolor=#99ccff bordercolor=#000066>") For j=0 to Columns.Count-1 Response.Write("<td><font size=2>"&Columns(j)&"</font></td>") Next Response.Write("</tr>") rs.movenext if rs.EOF then exit for Next Response.Write("</table>") END IF
%>
</BODY>
</HTML>