首页 > 应用开发 > IT综合 > 基于组件的asp编程之二--分页对象 (转)
在asp中,分页使用的最多的程序段了,把分页写成函数,调用起来,要传很多参数,写成对象,可以使分页
对象调用简单,本文在参考众多网友的分页函数基础上,用Javascript把它写成了一个对像放于文件
夹"_ScriptCom"下,文件名为"JPageNavbar.asp",先看一下分页对象的调用方式(由于大多数的asp开发人员使
用vbscript,所以本文的实例采用vbscript编写): ID="Table1"> onclick="gofind()" ID="Button1" NAME="Button1"> class="t_table" ID="Table2">
<!--#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
'***********************************************************************************
%>
:::学生信息搜索结果:::
==>>查询条件: <%=xshstr %>
<%
'***************************************************
fy.pnDisplay() '分页的“上一页” “下一页”
'***********************************************************
%>
学号
姓名
性别
年级
专业
二级学院
状态
<% i=0
'********************************************************
while (not rs.eof and i
%>
')"><%= rs("stu_num") %>
<%= rs("name") %>
<%= rs("sex") %>
<%= rs("gread") %>
<%= rs("speciality_name") %>
<%= rs("secondary") %>
<%=gd(rs("graduate")) %>
<% i=i+1
rs.moveNext
wend %>
<%
'**************************************************************
fy.plDisplay() '分页列表
'**************************************************************
%>
<%
rsNull(rs)
connNull(conn)
%>
这里是分页显示的效果图(做了一下处理)

这里是源代码
本文原名:asp分页的基于对象的解决
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10748419/viewspace-960564/ ,如需转载,请注明出处,否则将追究法律责任。