晕……
下次传上去!
[此贴子已经被作者于2004-06-24 20:20:38编辑过]
我的有上一页,下一页,数字页,第一页和最后一页
<!--#include file="conn.asp"--> <head> <meta http-equiv="Content-Language" content="zh-cn"> </head>
<% sql="select * from allbook order by id desc" set rs=server.createobject("adodb.recordset") rs.open sql,conn,1,1 if rs.recordcount=0 then 'rs.recordcount 所有记录数' response.write("数据库没有相关信息") else pgsz=5 rs.pagesize=cint(pgsz) totel=rs.recordcount pagecount=int(totel/pgsz*-1)*-1 pageno=request("pageno") 'pageno为当前页 if pageno="" then pageno=1 end if end if %> <% if (pageno-1)*pgsz<totel then rs.move pgsz*(pageno-1) '指针移到pgsz*(pageno-1)记录上 end if %> <% dim i i=0 do while not rs.eof and i<pgsz
%> <table cellpadding="0" cellspacing="0" width="770" height="119"> <!-- MSTableType="layout" --> <tr> <td valign="middle"> 书名:<%=rs("bookname")%></td> <td width="97"> 作者:<%=rs("zuozhe")%></td> <td width="173"> 出版社:<%=rs("chubanshe")%></td> <td width="140"> 出版时间:<%=rs("outtime")%></td> <td width="123"> 类别:<%=rs("leibie")%></td> <td height="23" width="117"> 价钱:<%=rs("piece")%></td> </tr> <tr> <td valign="top" width="120"> </td> <td valign="top" colspan="5" height="96"> <table style="table-layout:fixed" border="0" width="100%" cellspacing="0" cellpadding="0" id="table1"> <tr> <td width="61" style="word-break:break-all" valign="top">简介:</td> <td><%=rs("jianjie")%></td> </tr> </table> </td> </tr> </table>
<%rs.movenext loop %> </div>
<div align="center"> <table cellpadding="0" cellspacing="0" width="770" height="20"> <!-- MSTableType="layout" --> <tr> <td valign="top" height="20" width="770"><a href="fenye.asp?pageno=1"> <span style="text-decoration: none">第一页</span></a>| <% if pagecount>1 then a=pageno-1 b=pageno+1 if a>0 then response.write "<a href=fenye.asp?pageno=" response.write a response.write "><<<</a>| " end if for i=1 to pagecount response.write "<a href=fenye.asp?pageno=" response.write i response.write ">" response.write i response.write"</a> " next if pageno*pgsz<totel then response.write " |<a href=fenye.asp?pageno=" response.write b response.write ">>>></a> |" end if response.write "<a href=fenye.asp?pageno=" response.write pagecount response.write "><span style='text-decoration: none'>最后一页</span></a>" end if %> <% rs.close set rs=nothing %> <% closeconn %></td> </tr> </table> </div>
'设置一个recordset页面。在这个例子里,我们已有一个已经做好的数据库,并且把分页的每一页设为显示一条记录 dim conn ' ADO connection Dim RS' Recordset Dim sSQL ' SQL Get 'if Pagenum = "" Then Pagenum = 1 Set conn = server.createobject("ADODB.connection") Conn.Open"DSN=DatabaseName "set RS = Server.CreateObject("adodb.RecordSet") sSQL = "Select * From tblOrders" Rs.Open sSql, Conn, 3 ' 建立单个页 RS.Pagesize = 1 ' 设置在每页显示多少条记录iCnt = RS.PageCount ' 得到recordset里的记录总数 Select Case Request("NAV")
Case "" session("Pagenum") = 1 case "First" ' First Record session("Pagenum") = 1 case "Prev" ' Previous Record if session("Pagenum") > 1 then session("Pagenum") = session("Pagenum") - 1 End If case "Next" ' Next Record if session("Pagenum")< RS.PageCount then session("Pagenum") = session("Pagenum") + 1 End if case "Last"
' Last Record session("Pagenum") = RS.PageCount End Select ' 转到指定的页面(这里是session("pagenum") RS.Absolutepage = Clng(session("Pagenum")) ' // 在Form中显示记录转移 ' // 记录转移按钮设置 <form method="GET" action="secureorder.asp"> <p>
<input type="submit" name="NAV" Value="First">
<input type="submit" value="Prev" name="NAV">
<input type="submit" value="Next" name="NAV">
<input type="submit" value="Last" name="NAV"></p> </form>
我写了一个MyRecordSet类,可以通过设置一些属性自动分页输出到Table中,效果图如下:
以下是实现代码(类代码没有列出):
<% If Request.Form("Action")<>"" Then
'获取提交的查询条件 LineName=Replace(Trim(Request.Form("LineName")),"'","''") LineType=Replace(Trim(Request.Form("LineType")),"'","''") GroupGrade=Replace(Trim(Request.Form("GroupGrade")),"'","''") DayNum=Request.Form("DayNum") StatesAll=Request.Form("StatesAll") States=Request.Form("States") StartDate1=Request.Form("StartDate1") StartDate2=Request.Form("StartDate2") With MyRecordSetObj .Filter="" '用MakeSQL方法生成查询条件 If States<>"" Then .MakeSQL "B.strName","num","in","(" & States & ")","" End If .MakeSQL "A.strLineName","text","like",LineName,"" .MakeSQL "A.strLineType","text","like",LineType,"" .MakeSQL "A.strGroupDegree","text","like",GroupGrade,"" .MakeSQL "DayNum","num","=",DayNum,"" .MakeSQL "A.dtBeginTime", "date", "between",StartDate1,StartDate2 Cond=.Filter End With SqlStr="SELECT *, (A.dtEndTime - A.dtBeginTime + 1) AS DayNum FROM T_Group_BaseInfor A Inner Join T_B_Team_State B On A.intGroupState = B.lngID" If Cond<>"" Then SqlStr=SqlStr & " Where " & Cond End If Session("GroupLineSQL")=SqlStr MyRecordSetObj.AbsolutePage=1 ElseIf Session("GroupLineSQL")<>"" And Request.QueryString("Page")<>"" Then SqlStr=Session("GroupLineSQL") MyRecordSetObj.AbsolutePage=Request.QueryString("Page") Else SqlStr="SELECT *, (A.dtEndTime - A.dtBeginTime + 1) AS DayNum FROM T_Group_BaseInfor A Inner Join T_B_Team_State B On A.intGroupState = B.lngID Where B.strName='正在报名'" Session("GroupLineSQL")=SqlStr MyRecordSetObj.AbsolutePage=1 End If 'Response.Write(SqlStr) With MyRecordSetObj '清除属性 .ClearProperty .Options="" .PageSize=10 '每页记录数 '.CursorType=1 .CursorLocation=3 .RecordSource=SqlStr
'●设置表格属性(按HTML语法设置)● .TbProperty="id=GroupList onmousemove=""JavaScript:MouseTrace('GroupList','GroupListHead','TR','#0A246A','#FFFFFF')"" bgcolor=#999999 width=98% border=0 cellspacing=1 cellpadding=3" '设置表格属性(参数为 属性名,属性值) '.SetTbProperty "cellspacing",2 '●设置表格表头行属性(按HTML语法设置)● .TbHeadTRProperty="id=GroupListHead bgcolor=white align=center style=font-weight:bold" '设置表格表头行属性(参数为 属性名,属性值) .SetTbHeadTRProperty "align","center" '●设置表格表头列属性(按HTML语法设置,每列的属性之间以|隔开)● .TbHeadColProperty="||align=left" '●设置表格数据行属性(按HTML语法设置,%字段名%代替字段值,(不能用%this%) 每行的属性之间以|隔开,若总行数超过设置的行数,则循环使用)● .TbDataTRProperty="id='%Group_id%' align='center' bgcolor='#F7F7F7'|id='%Group_id%' align='center' bgcolor='#E6E6E6'" '●设置要显示的数据表字段名称,用,隔开● .FieldsList="strGroupID,dtBeginTime,strLineName,DayNum,strGroupDegree,intMaxNum,strName," '●设置要显示的数据表字段中文名称,用,隔开(可使用HTML代码)● .FieldsNameList="团号,发团日期,线路名,天数,团队等级,最大/已报人数,状态,操作" '●设置表格数据列属性(列之间以|隔开)● .TbDataColProperty="||align=left" '●设置表格数据列值规则(列之间以|隔开,%字段名%代替字段值)● .TbDataColValue="|||||%this%/%intTotalNum%||<a href=""viewGroup.asp?GroupID=%Group_ID%"" title=""查看该团队线路详细信息"">查看</a> <a href=""Register.asp?GroupID=%Group_ID%&Type=Single"" title=""散客报名"">报名</a>" .toTable '输入出到Table中 %> <table width="98%"> <tr> <td>共 <font color=red><%=.PageCount%></font> 页 第 <font color=red><%=.AbsolutePage%></font> 页</td> <td align=right> <% .ShowPage .AbsolutePage,.PageCount,"Page" '显示分页(上一页 下一页) End With
%>
[此贴子已经被作者于2004-06-25 15:03:31编辑过]