怎样在ASP中对记录分页显示?
<%
Dim Sql,Rs,j
Set Rs=Server.CreateObject( "ADODB.RecordSet ")
Sql= "Select * From news where class=1 and tjnews=1 Order By Id Desc "
Rs.Open Sql,Conn,1,3
RsCount=Rs.RecordCount
%>
<%
for j=1 to RsCount
%>
<table width= "100% " border= "0 " cellpadding= "0 " cellspacing= "0 " bgcolor= "#FAFAFA ">
<tr style= "height:25px ">
<td width= "10% "> </td>
<td width= "75% " style= "FONT-SIZE: 12px; LINE-HEIGHT: 180% "> <a href= " <%=Rs( "FilePath ")%> <%=Rs( "FileName ")%> " target= "_blank " "> <font color= "red "> <%=Rs( "title ")%> </font> </a> </td>
<td width= "15% " style= "FONT-SIZE: 12px; LINE-HEIGHT: 180% "> <font color= "#999999 "> <%=year(Rs( "addtime "))%> - <%=month(Rs( "addtime "))%> - <%=day(Rs( "addtime "))%> </font> </td>
</tr>
<tr> <td bgcolor= "#EAEAEA " colspan= "3 " height= "1 "> </td> </tr>
</table>
<%
Rs.movenext
next
%>
<%
Rs.close
set Rs=Nothing
%>
现在我想在这基础上实现每页显示20条记录,多余的就分页显示,分页效果如下:
首页 上一页 下一页 末页 输入某页回车就到某页
该如何实现?
[解决办法]
'******************************************************************************************************************
'分页器
Function PageBreak(Record,PageNum,ByVal RecordMax,ByVal Action,ByVal Hidden)
Dim PageTemp,i,MaxPage
PageBreak = " "
if Record = " " then
Record = 15
else
if IsNumeric(Record) then
Record = cint(Record)
else
Record = 15
end if
end if
if Record > RecordMax then
Record = RecordMax
end if
if Record < 1 then
Record = 1
end if
MaxPage = RecordMax \ Record
IF (RecordMax Mod Record)> 0 Then
MaxPage = MaxPage + 1
End If
if PageNum = " " then
PageNum = 1
else
PageNum = cint(PageNum)
end if
if PageNum > MaxPage then PageNum = MaxPage
if PageNum < 1 then PageNum = 1
PageBreak = PageBreak & " <form method= " "get " " action= " " " & Action & " " "> "
PageBreak = PageBreak & Hidden
PageBreak = PageBreak & " <div style= " "float: left;width:26%;padding: 10px 0px 0px 0px;text-align : center; " "> "
PageTemp = 1
if MaxPage> 1 then
if PageNum > 1 then
PageBreak = PageBreak & " <a href= " "# " " onclick= " "JScript:this.parentNode.parentNode.PageNum.value= '1 ';this.parentNode.parentNode.submit();return false; " "> 首页 </a> "
PageBreak = PageBreak & " <a href= " "# " " onclick= " "JScript:this.parentNode.parentNode.PageNum.value= ' " & PageNum-1 & " ';this.parentNode.parentNode.submit();return false; " "> 前页 </a> "
else
PageBreak = PageBreak & "首页 前页 "
end if
if PageNum <MaxPage then
PageBreak = PageBreak & " <a href= " "# " " onclick= " "JScript:this.parentNode.parentNode.PageNum.value= ' " & PageNum+1 & " ';this.parentNode.parentNode.submit();return false; " "> 后页 </a> "
PageBreak = PageBreak & " <a href= " "# " " onclick= " "JScript:this.parentNode.parentNode.PageNum.value= ' " & MaxPage & " ';this.parentNode.parentNode.submit();return false; " "> 尾页 </a> "
PageTemp = PageNum + 1
else
PageBreak = PageBreak & " 后页 尾页 "
end if
else
PageBreak = PageBreak & "首页 前页 后页 尾页 "
end if
PageBreak = PageBreak & " </div> "
PageBreak = PageBreak & " <div style= " "float: right;width:30%;text-align : center; " "> 转到: <select name= " "PageNum " "> "
for i = 1 to MaxPage
PageBreak = PageBreak & " <option value= " " " & i & " " " "
if i = PageTemp then
PageBreak = PageBreak & " selected= " "selected " " "
end if
PageBreak = PageBreak & "> " & i & " </option> "
next
PageBreak = PageBreak & " </select> <button class= " "SolidButton " " onclick= " "JScript:this.form.submit(); " "> <img border= " "0 " " src= " "/Images/Goto.Gif " " align= " "absbottom " " /> 翻页 </button> "
PageBreak = PageBreak & " </div> "
PageBreak = PageBreak & " <div style= " "padding: 3px 0px 0px 0px;text-align : center; " "> "
PageBreak = PageBreak & "共 " & RecordMax & "条信息 每页 <input maxlength= " "4 " " class= " "MyText " " valueType= " "integer " " type= " "text " " name= " "Record " " size= " "2 " " value= " " " & Record & " " " /> 条 页次: <span style= " "font-weight:bold;color:red " "> " & PageNum & " </span> / " & MaxPage & "页 "
PageBreak = PageBreak & " </div> "
PageBreak = PageBreak & " </form> "
End Function
'*******************************************************************************************************************
调用方法:
'分页
Record = Request( "Record ")
PageNum = Request( "PageNum ")
StrPage = PageBreak(Record,PageNum,Reco.RecordCount, "Program.Asp ", " <input type= 'hidden ' name= 'ProgramType ' value= ' " & ProgramType & " '> ")
Reco.Pagesize = Record
Reco.AbsolutePage = PageNum
i = 0
在table结束处输入: <%=StrPage%>
这样分页就出来了,这个分页器十分不错哦。。。。。
[解决办法]
<table width= "98% " height= "425 " border= "0 " cellpadding= "0 " cellspacing= "0 " background= "../images/07.gif ">
<tr>
<td height= "36 " valign= "top " bgcolor= "#FFFFFF "> </td>
</tr>
<tr>
<td height= "323 " valign= "top "> <table width= "90% " border= "0 " cellspacing= "3 " cellpadding= "0 ">
<tr>
<td height= "24 " valign= "top "> 当前位置: <a href= "../index.asp " class= "STYLE6 "> 首页 </a> >>XX新闻 </td>
</tr>
</table>
<%
set rsnews=server.CreateObject( "adodb.recordset ")
sqlnews= "Select * from news where cataid =1 order by id desc "
rsnews.Open sqlnews,conn,1,1
rcount=rsnews.recordcount
if pmcount= " " or isempty(pmcount) or pmcount <1 then
pmcount=20
end if
rsnews.pagesize=pmcount
mpage=rsnews.pagecount
pageno=request( "pageno ")
if isempty(pageno) or cint(pageno) <1 or cint(pageno)> mpage then
pageno=1
end if
if rsnews.bof and rsnews.eof then
response.write " <div align= 'center '> 没有新闻 </div> "
else
rsnews.absolutepage=pageno
loopno=pmcount
do while not rsnews.eof and loopno> 0
%>
<table width= "81% " border= "0 " align= "center " cellpadding= "0 " cellspacing= "0 ">
<tr>
<td width= "2% "> <div align= "center ">
<p class= "unnamed1 "> </p>
</div> </td>
<td width= "98% " height= "24 " class= "wordwhite "> <a href= "readnews.asp?id= <%=rsnews( "id ")%> " target= "_blank "> <font color= "#000000 "> <%=rsnews( "title ")%> </font> </a> [点击: <font color= "#FF0000 "> <%=rsnews( "hits ")%> </font> 次] </td>
</tr>
</table>
<%
rsnews.movenext
loopno=loopno-1
loop
end if
'rsnews.close
'set rsnews=Nothing
'endconnection%>
<table width= "81% " border= "0 " align= "center " cellpadding= "0 " cellspacing= "0 ">
<tr>
<td height= "48 " class= "word "> <div align= "center ">
<p class= "wordwhite "> 共 <font color= "#FF0000 "> <%=cstr(rcount)%> </font> 条信息 当前第 <font color= "#FF0000 "> <%=cstr(pageno)& "/ "&cstr(mpage)%> </font> 页 每页 <font color= "#FF0000 "> <%=pmcount%> </font> 条
<%
if cint(pageno)> 1 then%>
[ <a href= 'smallclass.asp?sss= <%=sss%> &%20ttt= <%=ttt%> &pageno= <%=pageno-1%> '> 上一页 </a> ]
<%
end if
if cint(pageno) <cint(mpage) then
%>
[ <a href= 'smallclass.asp?sss= <%=sss%> &%20ttt= <%=ttt%> &pageno= <%=pageno+1%> ' > <font color= "#FF0000 "> 下一页 </font> </a> ]
<%end if%>
</p>
</div> </td>
</tr>
</table> </td>
</tr>
</table>