洪洋洞唱词:高手帮忙,asp分页显示有错误

来源:百度文库 编辑:神马品牌网 时间:2024/05/07 03:12:25
<%
const numperpage=3
Dim pageon
if Request.QueryString("pageon") = "" then
pageon = 1
Else
pageon = Request.QueryString("pageon")
End If
Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
Conn.Open "new"

Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")

rs.CacheSize = numperpage
Dim strSQL
strSQL = "SELECT * FROM news ORDER BY id DESC"
rs.Open strSQL, Conn

rs.MoveFirst
rs.PageSize = numperpage
Dim TotalPages
TotalPages = rs.PageCount
dim total
total=rs.recordcount
dim ScrollAction
ScrollAction = Request("ScrollAction")
if ScrollAction = " 上一页 " Then
PageNo=PageNo-1
end if
if ScrollAction = " 下一页 " Then
PageNo=PageNo+1
end if
if pageno<1 then
pageno=1
end if
%>
</p>
<p align="center"><span class="STYLE2">新闻浏览</span></p>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="747" height="28" border="1" align="left">
<tr>
<th width="144" scope="col">共有<%=TotalPages%>篇文章</th>
<th width="183" scope="col">第<%=pageon%>/<%=TotalPages%>页</th>
<th width="398" scope="col"><div align="right"><a href="fabu.asp">新闻发布</a></div></th>
</tr>
</table>
<p> </p>
<table width="600" border="1" align="center">
<tr>
<td width="164" scope="col"><div align="center">新闻标题</div></td>
<td width="138" scope="col"><div align="center">时间</div></td>
<td width="126" scope="col"><div align="center">发布部门</div></td>
<td width="144" scope="col"><div align="center">内容</div></td>
</tr>
<tr>
<%

count=0
do while not rs.EOF and count<rs.pagesize
%>
<td scope="col"><div align="center"><%=rs("title")%></div></td>
<td scope="col"><div align="center"><%=rs("date")%></div></td>
<td scope="col"><div align="center"><%=rs("bumen")%></div></td>
<td scope="col"><div align="center"><%=rs("text")%></div></td>
</tr>
</table>
<%
Count=Count+1
RS.MoveNext
Loop

Conn.Close
set rs = nothing
set Conn = nothing
%>
</table>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>

<td height="15"><input type="hidden" name="pageno" value="<%=pageno%>">
<tr>
</table>
<%
if PageNo>1 Then
response.write "<INPUT TYPE=SUBMIT NAME='ScrollAction' VALUE='上一页'>"
end if
if Count =numperpage and PageNo <>TotalPages then
response.write "<INPUT TYPE=SUBMIT NAME='ScrollAction' VALUE='下一页'>"
end if
%>
<label></label>
<label></label>
</form>

分页显示错误,太广了吧,详细点,比如:分页显示不了,参数都传对的,可是还是显示在第一页!检查了所有的分页设置,都是正确的,那就是一个很捣蛋的问题了! 就是变量与变量比较,如果是数值的话要强制数值比较,如:int(count)<int(page_size)我以前弄分页时也是因为这个,
而你的分页方式显然跟我的不一样,我是使用
rs.absolutePage = ipage
而不管怎么样,得保证 ipage不会超出范围,而在你的设置中,pageon好象是在一开始检查,然后修改的,这明显有超出范围的可能性!比如:在第一页还上一页,那肯定出错,还有最后一页也一样!
你看看我的这个吧!
<%
sub showNews(sql,rows,cols,ipage,isShowBookMark,autoLen)
dim rs,page_size,icol,path
if cols="" or not isNumeric(cols) then cols = 1
if cols<=0 then cols = 1
if rows="" or not isNumeric(rows) then rows = 1
if rows<=0 then rows=1
if ipage="" or not isNumeric(ipage) then ipage=1
if ipage<=0 then ipage=1
if autoLen="" or not isNumeric(autoLen) then autoLen = 20
if autoLen<=0 then autoLen = 20

page_size = cols * rows
set rs = server.CreateObject("ADODB.recordset")
rs.open sql,conn,1,1
response.write "<table width=100% border=0 cellpadding=0 cellspacing=0 id=news>" & VBCRLF
if rs.eof or rs.bof then
response.write "<tr><td width=100% height=50 align=center valign=middle style='color:red'>暂时没有信息!</tr>" & VBCRLF
response.write "</table>" & VBCRLF
exit sub
end if
rs.pageSize = page_size
if int(ipage) > int(rs.pageCount) then ipage = rs.pageCount
rs.absolutePage = ipage

icol = 0
while not rs.eof and int(icol)<int(page_size)
if icol mod cols = 0 then
response.write "<tr>" & VBCRLF
end if
response.write "<td width=" & int(100/cols) & "% height=20 align=left valign=middle>" & VBCRLF
%>  ·<a href="readData.asp?id=<%=rs("id")%>&DataType=10001" target="_self"><%=autoCut(rs("title"),autoLen)%></a> <span id="time">[<%=DateValue(rs("post_time"))%>](已阅<%=rs("click_count")%>次)</span>
<%
response.write "</td>" & VBCRLF
icol = icol + 1
if icol mod cols = 0 then
response.write "</tr>" & VBCRLF
end if
rs.movenext
wend
if icol mod cols <> 0 then
response.write "<td colspan=" & int(cols - icol mod cols) & "> </td></tr>" & VBCRLF
end if
response.write "</table>"

if isShowBookMark=1 then

dim reg
set reg = new RegExp
reg.pattern = "[&]*page=[0-9]*"
reg.Global = true
reg.Ignorecase = true
path = reg.replace(request.QueryString,"")
if path="" then
path = "?" & path
else
path = "?" & path & "&"
end if
set reg = nothing

response.Write "<br><div style='font-size:12px;color:black'>" & VBCRLF
response.write "<br>总记录数<span style='color:red'>"&rs.recordCount&"</span>   每页<span style='color:red'>" & page_size & "</span>  "
if ipage <= 1 then
response.write "<span style='color:darkgray'>首页 前页</span>"
else
response.write "<a href=" & path & "page=1>首页</a> <a href=" & path & "page="&ipage-1&">前页</a>"
end if
if int(ipage) = int(rs.pageCount) then
response.write "<span style='color:darkgray'> 下页 末页</span>"
else
response.write " <a href=" & path & "page="&ipage+1&">下页</a> <a href=" & path & "page="&rs.pageCount&">末页</a>"
end if
response.write "    第"&ipage&"页 共"&rs.pageCount&"页"
response.write "</div>"

end if
end sub
%>

rs.Open strSQL, Conn
换成.1.3打开方式看看