欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

分页代码

程序员文章站 2022-05-03 16:32:52
分页代码: <%''本程序文件名为:pages.asp%> <%''包含ado常量表文件adovbs.inc,可从"\program fil...
 

分页代码:
<%''本程序文件名为: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>