首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

不能分页,该怎么解决

2012-02-11 
不能分页!--#includefile conn.asp --%setrsserver.CreateObject( adodb.recordset )sql selec

不能分页
<!--#include   file= "conn.asp "-->
<%   set   rs=server.CreateObject( "adodb.recordset ")
  sql= "select   *   from   user "
  if   session( "userlimit ") <1   then   sql=sql& "   where   user_name= ' "&session( "username ")& " ' "
  sql=sql& "   order   by   user_name   desc "
  rs.open   sql,conn,1,1
  rs.pagesize=2
  PageNo=request( "PageNo ")
  if   request( "pagerno ")= " "or   request( "pageno ") <=1   then   pageno=1
  totalpages=rs.pagecount
  if   request.servervariables( "content_length ")   >   0   then
currentpage=1
else
currentpage=clng(PageNo)
end   if
if   currentpage> totalpages   then   currentpage=totalpages  
if   not(rs.eof)   then   rs.absolutepage   =   currentpage
  %>
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> 显示用户 </title>
</head>

<body>
<table   width= "98% "   border= "0 "   align= "center "   cellpadding= "0 "   cellspacing= "0 ">
    <tr>
        <td>
            <table   width= "100% "   border= "0 "   cellpadding= "0 "   cellspacing= "1 "   bgcolor= "#F4F9FF ">
                <tr   bgcolor= "#E3E8F9 ">  
                    <td   width= "20 "   height= "15 "> &nbsp; </td>
                    <td   height= "15 ">   <div   align= "center "> <font   size= "2 "> <strong> 用   户   名 </strong> </font> </div> </td>
                    <td   width= "80 "   height= "15 ">   <div   align= "center "> <font   size= "2 "> <strong> 用户类型 </strong> </font> </div> </td>
                    <td   width= "80 "   height= "15 ">   <div   align= "center "> <font   size= "2 "> <strong> 管理 </strong> </font> </div> </td>
                </tr>
                <%
rowcount=(currentpage   -   1)*rs.pagesize
for   i=1   to   rs.pagesize                                      
if   rs.eof   then   exit   for
%>
                <tr   bgcolor= "#F4F8FF ">  
                    <td>   <div   align= "center "> <img   src= "images/icon9.gif "   width= "8 "   height= "10 "> </div> </td>


                    <td   height= "20 "> <font   size= "2 "> <a   href= "showuser.asp?user_name= <%=rs( "user_name ")%> "> <%=left(rs( "user_name "),22)%>  
                        <%if   len(rs( "user_name "))> 22   then   response.write   "…… "%>
                        </a> </font> </td>
                    <td>   <div   align= "center "> <font   size= "2 "   color= "#999999 ">
    <%
    if   rs( "user_limit ")=0   then   response.write   "信息员 "
    if   rs( "user_limit ")=1   then   response.write   "管理员 "
   
    %>
    </font> </div> </td>
                    <td>  
                        <div   align= "center "> <font   size= "2 "> <a   href= "edituser.asp?user_name= <%=rs( "user_name ")%> &pageno= <%=currentpage%> "> 编辑 </a>  
<%if   session( "userlimit ")> 0   and   rs( "user_name ") <> session( "username ")   then%> <a   href= "javascript:if(confirm( '您确定要删除此条信息? '))   window.location.href= 'deluser.asp?user_name= <%=rs( "user_name ")%> &pageno= <%=currentpage%> ' "> 删除 </a> <%end   if%> </div> </td>
                </tr>
<%
rs.movenext
next
%>
                <tr   bgcolor= "#E6EFFF ">  
                    <td   height= "20 "   colspan= "4 ">
    <div   align= "center ">
 
<%if   currentpage> 1   then%>
<a   href= "?pageno=1 "> <font   color= "#000000 "   size= "2 "> 第一页 </font> </a>
<a   href= "?pageno= <%=currentpage-1%> "> <font   color= "#000000 "   size= "2 "> 上一页 </font> </a>  
<%end   if                                                                                                                                                                                  
if   currentpage   <   totalpages   then                                              


%>
<a   href= "?pageno= <%=currentpage+1%> "> <font   color= "#000000 "   size= "2 "> 下一页 </font> </a>
<a   href= "?pageno= <%=totalpages%> "> <font   color= "#000000 "   size= "2 "> 最后一页 </font> </a>  
<%end   if%>
<font   color= "#000000 "   size= "2 "> &nbsp;共 <%=totalpages%> 页   共&nbsp; <%=rs.recordcount%> &nbsp;条
转到第
            <select   name= "sel_page "   onChange= "javascript:location=this.options[this.selectedIndex].value; ">
            <%
              for   i   =   1   to   rs.PageCount
              if   i   =   currentpage   then%>
              <option   value= "?pageno= <%=i%> "   selected> <%=i%> </option>
            <%else%>
              <option   value= "?pageno= <%=i%> "> <%=i%> </option>
            <%
            end   if
            next
            %>
          </select> 页   </font>
</div> </td>
                </tr>
            </table>
           
        </td>
    </tr>
</table>
</body>
</html>

不能分页,帮忙解决一下吧

[解决办法]
<!--#include file= "Conn.asp "-->
<table width= "476 " border= "0 " cellspacing= "0 " cellpadding= "0 ">
<tr>
<td> <img src= "Images/listhangye.gif " width= "476 " height= "24 " border= "0 " usemap= "#Map "> </td>
</tr>
<tr>
<td> <img src= "Images/listtop.gif " width= "476 " height= "14 "> </td>
</tr>
<%
Set Rs=Server.CreateObject( "Adodb.RecordSet ")
dim MaxPerPage '单独页最大记录数 const 用来申明常量
dim totalPut
dim CurrentPage
dim TotalPages
dim ipage
MaxPerPage=18
'查询语句=======================
Sql= "Select * From News order by id Desc "
Rs.Open Sql,Conn,1,1
'===============================

if not Rs.eof then
Rs.MoveFirst
end if
Rs.pagesize=MaxPerPage
If trim(Request( "Page ")) <> " " then
If IsNumeric(trim(Request( "Page "))) = False Then
%>
<script language= "javascript "> alert( '页面参数错误! ');history.go(-1); </script>
<%
End If
CurrentPage= CLng(request( "Page "))
If CurrentPage> Rs.PageCount then
CurrentPage = Rs.PageCount
End If
Else
CurrentPage= 1
End If

totalPut=Rs.recordcount


if CurrentPage <> 1 then
if (currentPage-1)*MaxPerPage <totalPut then
Rs.move(currentPage-1)*MaxPerPage
dim bookmark
bookmark=Rs.bookmark
end if
end if

dim n,k
if (totalPut mod MaxPerPage)=0 then
n= totalPut \ MaxPerPage
else
n= totalPut \ MaxPerPage + 1
end if


If Not Rs.Eof Then
Do While Not Rs.Eof and ipage <MaxPerPage
%>
<tr>
<td height= "24 " background= "Images/listbg.gif "> <table width= "98% " border= "0 " cellspacing= "0 " cellpadding= "0 ">
<tr>
<td width= "7% "> &nbsp; </td>
<td width= "81% "> <a href= "NewsShow.asp?sid= <%=Rs( "ID ")%> " title= " <%=Rs( "Title ")%> "> <%=gotTopic(Rs( "Title "),56)%> </a> <% if rs( "imagenum ") <> "0 " then response.write " <img src= 'images/news.gif ' border=0 alt= '图片新闻 '> " end if %> </td>
<td width= "12% "> [ <%=Mid(Rs( "Infotime "),6,10)%> ] </td>
</tr>
</table> </td>
</tr>
<%
Rs.MoveNext
ipage=ipage+1
Loop
Else
%>
<tr>
<td colspan= "3 " height= "24 " background= "Images/listbg.gif ">     暂无新闻信息! </td>
</tr>
<%
End If
Rs.Close
%> <tr>
<td> <img src= "Images/listbottom.gif " width= "476 " height= "15 "> </td>
</tr>
</table>
<table width= "100% " border= "0 " align= "center " cellpadding= "0 " cellspacing= "0 ">
<tr>
<td align= "center ">
<%
k=currentPage
if k <> 1 then
response.write "[ <b> "+ " <a href= 'News.asp?page=1 '> 首页 </a> </b> ] "
response.write "[ <b> "+ " <a href= 'News.asp?page= "&cstr(k-1)& " '> 上一页 </a> </b> ] "
else
Response.Write "[首页] [上一页] "
end if
if k <> n then
response.write "[ <b> "+ " <a href= 'News.asp?page= "&cstr(k+1)& " '> 下一页 </a> </b> ] "
response.write "[ <b> "+ " <a href= 'News.asp?page= "&cstr(n)& " '> 尾页 </a> </b> ] "
else
Response.Write "[下一页] [尾页] "
end if
Response.Write " <font color= '#ff0000 '> "&currentpage& " </font> / "&n& "页 "&MaxPerPage& " 条/页 "
Response.Write " 共 <font color= '#FF0000 '> "&totalPut& " </font> 条 "
%>
转到:
<select name= "select " onChange= "javascript:window.location= 'News.asp?page= '+this.options[this.selectedIndex].value; ">
<option> 跳转 </option>
<%
Dim z
For z=1 To n%>
<option value= " <%=z%> "> 第 <%=z%> 页 </option>
<%
Next
%>


</select> </td>
</tr>
</table>


News.asp

一个简单的分页例子

热点排行