面向对象的asp编程之二--分页对象(javascript版)

 

基于组件的asp编程之二--分页对象

 

  在asp中,分页使用的最多的程序段了,把分页写成函数,调用起来,要传很多参数,写成对象,可以使分页

对象调用简单,本文在参考众多网友的分页函数基础上,用javascript把它写成了一个对像放于文件

夹"_ScriptCom"下,文件名为"JPageNavbar.asp",先看一下分页对象的调用方式(由于大多数的asp开发人员使

用vbscript,所以本文的实例采用vbscript编写):
<%@LANGUAGE="VBSCRIPT" %>
<!--#include file="../connections/dbconn.asp" -->
<!--#include file="../_ScriptCom/FAdodb.asp" -->
<!--#include file="../_ScriptCom/FSession.asp" -->
<!--#include file="../_ScriptCom/JPageNavbar.asp" -->
<%
   Response.Buffer=true
   on error resume next
   
   if trim(Request.ServerVariables("REQUEST_METHOD")) = "POST" then
      '取得查询字符串
       chxstr=readForm("chxstr")   
        xshstr=readForm("xshstr")   
        r1=readForm("R1")
       '保存查询条件
       session("r1")=r1
       session("chxstr")=chxstr
       session("xshstr")=xshstr 
   else
       如果不是从form提交,则是分页,从session取的查询条件
        r1=readSession("r1")
        chxstr=readSession("chxstr")
        xshstr =readSession("xshstr")
   end if
  
  '这里是一些关于业务的逻辑运算
  if xshstr=empty then
       xshstr ="查询所有记录"
   end if
   
    select case r1
    case 1 '在校学生
        sql=" select * from v_student_base where  graduate=0"
        if chxstr<>empty then
           sql=sql+"  and "+ chxstr
        end if 
        cddr="在校学生"
    case 2 ' 毕业学生   
        sql=" select * from v_student_base where  graduate=1"
         if chxstr<>empty then
           sql=sql+"  and "+ chxstr
        end if 
       cddr="毕业学生"
    case 0 '全部学生   
       if chxstr<>empty then
          sql="select * from v_student_base where"+"  "+chxstr
       else
         sql="select * from v_student_base"
       end if
       cddr="全部学生"
   case else
       response.write "系统参数错误,请与系统管理员联系!"
       response.End
   end select
 
   '生成connection 和 Recordset
   set conn=connCreate(getDBLink())
   set rs=rsCreate()
   rs.open sql,conn,1,3
   if (rs.eof ) then
      show_msg "很遗憾,没有您要的记录!",4,"infoQuery.asp"
   end if
    dim gd(1)
 gd(0)="未毕业"
 gd(1)="已毕业"
 
  '***************************************************************************
  '注意:这里是分页
  RowCount =15
 set fy=createJPageNavbar()
 if (not isEmpty(rs)) then
  rs.PageSize = RowCount '设置数据集的页记录
  fy.PageSize=RowCount
  rs.AbsolutePage =fy.getCurrentPage()
  fy.RecordCount=rs.RecordCount
  fy.PageCount=rs.pageCount
  fy.PnWidth="100%"
  fy.PnAlign="center"
  fy.PlWidth="100%"  '表格宽度
  fy.PlAlign="right"  ' 表格的对齐方式
end if  
'***********************************************************************************
%>
<HTML>
<HEAD>
<TITLE>学生信息查询</TITLE>
<link href="../css/style.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY text="#000000" bgColor="#ffffff" leftMargin="0" topMargin="0">
<br>
<TABLE width="550" border="1" cellspacing="0" cellpadding="1" align="center" class="t_table"

ID="Table1">
  <TR>
    <TD colspan="2" class="t_head"> :::学生信息搜索结果::: </TD>
  </TR>
  <TR>
    <TD width="80%" align="left"><B>==&gt;&gt;查询条件:</B> <%=xshstr %></TD>
    <TD width="20%" align="right"><INPUT type="button" value="返回" class="button"

οnclick="gofind()" ID="Button1" NAME="Button1"> </TD>
  </TR>
  <TR>
    <TD colspan="2"><table width="100%" border="0" cellpadding="1" cellspacing="0"

class="t_table" ID="Table2">
        <tr align="center">
          <td colspan="7"><%
        '***************************************************
          fy.pnDisplay() '分页的“上一页” “下一页”
      '***********************************************************
          %></td>
        </tr>
        <tr>
          <td width="13%" class="t_head">学号</td>
          <td width="11%"  class="t_head">姓名</td>
          <td width="8%"  class="t_head">性别</td>
          <td width="10%"  class="t_head">年级</td>
          <td width="20%"  class="t_head">专业</td>
          <td width="28%"  class="t_head">二级学院</td>
          <td width="10%"  class="t_head">状态</td>
        </tr>
  <%  i=0
                 '********************************************************
    while (not rs.eof and i<RowCount)  '控制一页显示的记录条数
               '*********************************************************
%>
        <tr>
          <td width="13%" align="center"><a href="#"  οnclick="openWindow2('stu_msg.asp?

stu_num=<%= rs("stu_num")%>')"><%= rs("stu_num") %></a></td>
          <td width="11%" align="center"><%= rs("name") %></td>
          <td width="8%" align="center"><%= rs("sex") %></td>
          <td width="10%" align="center"><%= rs("gread") %></td>
          <td width="20%" align="center"><%= rs("speciality_name") %></td>
          <td width="28%" align="center"><%= rs("secondary") %></td>
          <td width="10%" align="center"><%=gd(rs("graduate")) %></td>
        </tr>
  <% i=i+1
     rs.moveNext
   wend %>
        <tr align="right">
          <td colspan="7"><%
'**************************************************************       
fy.plDisplay() '分页列表
'**************************************************************
         %></td>
        </tr>
      </table> </TD>
  </TR>
</TABLE>
</BODY>
</HTML>
<%
  rsNull(rs)
  connNull(conn)
%>

这里是分页显示的效果图(做了一下处理)


这里是源代码

<SCRIPT LANGUAGE=javascript RUNAT=Server>
// ************************************************************************
// Script Compont Object Model
// Design for Active Server Pages
//
// Copyright 2003  Version 1.0
// Made by newsunet
// 请不要删除这一段注释,自由传播,保留所有权
// ************************************************************************

/*//Ado.RecordSet记录分页对象
//设置分页
  var  RowCount =3
  var fy=new JPageNavbar()
   if (!rsRpt.Eof){
     rs.PageSize = RowCount //设置数据集的页记录
     fy.PageSize=RowCount
     rs.AbsolutePage =fy.getCurrentPage()
     fy.RecordCount=rs.RecordCount
     fy.PageCount=rs.pageCount
     fy.PnWidth="100%"
  fy.PnAlign="right"
  fy.PlWidth="100%"  //表格宽度
  fy.PlAlign="right"  // 表格的对齐方式

  }
 //显示分页
<%fy.pnDisplay()%>
<%fy.plDisplay()%>

*/
function createJPageNavbar(){

 //这个函数是vbscript的接口函数 ,vbscript不是基于对象的脚本语言
  var objJPageNavbar=new JPageNavbar
  return objJPageNavbar
}
function JPageNavbar(){
// public members
 this.PageSize="0"
 this.RecordCount="0" //总记录数
 this.PageCount="1"  //总页数
 this.CurrentPage="1"
 
 this.PnWidth="100%"
 this.PnAlign="right"
 this.PlWidth="100%"  //表格宽度
 this.PlAlign="right"  // 表格的对齐方式

 // private members
 
 //public methods
 this.getCurrentPage=_getCurrentPage
 this.pnDisplay = _PN_show;
 this.plDisplay = _PL_show;
 
 //private methods
 
}
 
    function _getCurrentPage(){
         //当前显示的是第几页
        
       //取得当前页
       var pageNo = Request.QueryString ("PageNo")
       //如果没有选择第几页,则默认显示第一页;
       if (isNaN(pageNo)) {
        pageNo = 1
       }
       this.CurrentPage=pageNo
       return pageNo
   }
   function  _PL_show(){
     
      var strBuilder=new String()
      strBuilder=""
      var p=(this.CurrentPage-(this.CurrentPage%10))/10 //计算分页显示的页数
      //首组为第0族
  
  strBuilder+="<table border=/"0/" cellpadding=/"0/" cellspacing=/"0/" "
     strBuilder+=" width=/""+this.PlWidth+"/"  align=/""+this.PlAlign+"/">"
    
     strBuilder+=" <tr> "
     strBuilder+=" <td valign=/"middle/" align=/"right/">分页:"
    
     if (this.CurrentPage==1){
    strBuilder+="<font face=/"webdings/"  color=/"#ff0000/">9</font> "
  } 
     else{
    strBuilder+="<a href=/"?PageNo=1/" title=/"首页/"><font face=/"webdings/">9</font></a>   "
  } 
     //上十页
     if (p*10>0){
       strBuilder+="<a href=/"?PageNo="+(p*10)+"/"  title=上十页><font

face=/"webdings/">7</font></a>   "
     } 
     strBuilder+="<b>"
      //分页列表
     for(var i=p*10+1;i<=p*10+10;i++){
        if (i==this.CurrentPage){
      strBuilder+="<font color=/"#000000/">"+i+"</font> "
     }
    else{
   strBuilder+="<a href=?PageNo="+i+" title=/"转到: 第"+i+"页/">"+i+"</a>   "
     }
    if (i>=this.PageCount) break;
  } 
  strBuilder+= "</b>"
      //显示下十页
      if (i<this.PageCount){
        strBuilder+="<a href=/"?PageNo="+i+"/" title=/"下十页/"><font

face=/"webdings/">8</font></a>   "
      } 
       //显示尾页
      if (this.CurrentPage==this.PageCount){
       strBuilder+= "<font face=/"webdings/" color=/"#000000/">:</font>   "
   }   
      else{
     strBuilder+= "<a href=?PageNo="+this.PageCount+" title=/"尾页/"><font

face=/"webdings/">:</font></a>   "
   } 
     strBuilder+= "</td></tr></table>"
     Response.Write(strBuilder)
  }
  function  _PN_show(){
    var strBuilder=new String()
    var nextPageNo
    strBuilder=""
    strBuilder+="<table border=/"0/"  cellpadding=/"0/" cellspacing=/"0/" "
    strBuilder+="  width=/""+this.PnWidth+"/" align=/""+this.PnAlign+"/">"
    strBuilder+="<tr>"
    strBuilder+="<td valign=/"middle/">页次:

[<b>"+this.CurrentPage+"</b>/<b>"+this.PageCount+"</b>]页 每页[<b>"+this.PageSize+"</b>]条 总记录

数:[<b>"+this.RecordCount+"</b>]条</td>"
    strBuilder+="<td align=/"right/">"
 if (this.CurrentPage>1){
   nextPageNo=this.CurrentPage
   nextPageNo--
      strBuilder+="[<a href=?pageNo="+nextPageNo+"  title=/"转到上一页/">上一页</a>]"
    }
    if (this.CurrentPage<this.PageCount){
      nextPageNo=this.CurrentPage
      nextPageNo++
      strBuilder+="[<a href=?pageNo="+nextPageNo+"  title=/"转到下一页/">下一页</a>]"
    }
 strBuilder+="</td></tr></table>"
 Response.Write(strBuilder)
  }

</SCRIPT>


本文原名:基于组件的asp编程之二--分页对象

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值