1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

请问ASP分页问题

本帖由 阿达2007-04-28 发布。版面名称:后端开发

  1. 阿达

    阿达 New Member

    注册:
    2005-12-06
    帖子:
    54
    赞:
    0
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <% if request("d")="add" then %>
    <!--#include file="conn.asp"-->
    <%
    if request.Form("xs_nj")="" or request.form("xs_zy")="" or request.form("xs_bj")="" then
    response.write "<script language=javascript>"
    response.write "alert('^_^请详细填写查询资料!^_^');"
    response.write "javascript:history.go(-1);"
    response.write "</script>"
    else
    xs_nj=request.Form("xs_nj")
    xs_zy=request.Form("xs_zy")
    xs_bj=request.Form("xs_bj")
    set rs=server.createobject("adodb.recordset")
    sql="select * from xsqk where xs_nj='"&xs_nj&"'and xs_zy = '"&xs_zy&"' and xs_bj = '"&xs_bj&"'"
    rs.open sql,conn,1,1
    %>
    <%
    '分页设置
    if not isempty(request("page")) then
    currentPage=cint(request("page"))
    else
    currentPage=1
    end if

    MaxPerPage=1 '###每页显示条数

    dim totalPut '总页数
    dim CurrentPage '当前页码
    dim TotalPages '总页数
    dim i,j
    %>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>梅州市技工學校信息化管理系統</title>
    <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
    <style type="text/css">
    <!--
    .bq {font-size:16px;
    line-height: 140%;
    }
    .STYLE7 {
    font-size: 18px;
    font-weight: bold;
    }
    .STYLE10 {font-size: 16px;}
    -->
    </style>
    </head>
    <body>
    <%
    if not rs.recordcount>0 then
    %>

    <div align="center"><p>&nbsp;</p><b>对不起,没有找到你想要的记录!<b><p></p><a href="index.asp">首页</a>&nbsp;&nbsp;<a href="xsqkcx.asp">继续查询</a></div>
    <%
    else
    %>
    <div align="center"><span class="STYLE7">梅州市技工学校&nbsp;<%=rs("xs_nj")%>&nbsp;<%=rs("xs_zy")%>&nbsp;<%=rs("xs_bj")%>&nbsp;学生基本情况查询结果</span>
    <br /><a href="index.asp">首页</a>&nbsp;&nbsp;<a href="xsqkcx.asp">继续查询</a>
    <br />页面:
    <%
    dim rsu,sqlu
    '并根据记录数进行分页显示。
    sqlu="select * from xsqk where xs_nj='"&xs_nj&"'and xs_zy = '"&xs_zy&"' and xs_bj = '"&xs_bj&"'order by id desc"
    Set rsu= Server.CreateObject("ADODB.Recordset")
    rsu.open sqlu,conn,1,1

    pageno=request("page")
    if MaxPerPage="" or isempty(MaxPerPage) or MaxPerPage<1 then
    MaxPerPage=15
    end if
    rsu.pagesize=MaxPerPage '得到每页数
    mpage=rsu.pagecount '得到总页数
    if isempty(pageno) or cint(pageno)<1 or cint(pageno)>mpage then
    pageno=1
    end if
    for pno=1 to mpage
    if pno=cint(pageno) then%><font color="#9999ff">【<font color="#FF0000"><b><%=pno%></b></font>】</font><%else%><font color="#9999ff">【<a href=xsqkcx.asp?d=add&id=<%=rsu("id")%>&page=<%=pno%> target="_self"><%=pno%></a>】</font><%end if%><%next%>
    <table aling="center" border="1" width="841" cellpadding="2" cellspacing="0">
    <tr align="center"><td><span class="STYLE10">姓名</span></td>
    <td><span class="STYLE10">学号</span></td>
    <td><span class="STYLE10">性别</span></td>
    <td><span class="STYLE10">年龄</span></td>
    <td><span class="STYLE10">民族</span></td>
    <td><span class="STYLE10">入学时间</span></td>
    <td><span class="STYLE10">毕业时间</span></td>
    </tr>
    <%
    k=(totalPut-MaxPerPage*(currentPage-1))+1
    do while not rs.eof
    k=k-1%>
    <tr align="center"><td><%=rs("xs_user") %>&nbsp;</td><td><%=rs("xs_xh") %>&nbsp;</td><td><%=rs("xs_xb")%>&nbsp;</td><td><%=rs("xs_nl") %>&nbsp;</td><td><%=rs("xs_nz")%>&nbsp;</td><td><%=rs("xs_lxtime")%>&nbsp;</td><td><%=rs("xs_bytime")%>&nbsp;</td>
    </tr>

    <% i=i+1
    if i>=MaxPerPage then exit do
    rs.movenext
    loop
    %></table><%end if %>
    </div>
    </body>
    <%
    rs.close
    set rs=nothing
    conn.close
    set rs=nothing
    end if
    %></html>
    <%else%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>梅州市技工學校信息化管理系統</title>
    <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
    <style type="text/css">
    <!--
    .STYLE2 {color: #FFFFFF}
    .STYLE6 {font-size: 14px}
    .bq {font-size:16px;
    line-height: 140%;
    }
    A:link{color:#ffffff;text-decoration:none}
    A:visited{color:#ffffff;text-decoration:none}
    A:active{color:#ff0000;text-decoration:none}
    A:hover{color:#ff0000;text-decoration:none}
    .STYLE12 {color: #FF0000}
    -->
    </style>
    </head>
    <!-- #include file="top1.inc" -->
    <!-- 导航条 -->
    <tbody>
    <tr>
    <td >
    <table width="778" bgcolor="#0089f7"height="30" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td width="100%">&nbsp;<span class="STYLE2"><img src="images/class_ar.gif">&nbsp;<span style="font-weight: bold">您当前的位置: <a href="index.asp">首页</a></span></span> <span class="STYLE2" style="font-weight: bold; color: #FFFFFF">-&gt;</span> <span class="STYLE2" style="font-weight: bold; color: #FFFFFF">学生基本情况查询</span></td>
    </tr></table></td></tr></tbody>

    <!-- BODY内客 1 -->
    <tbody>
    <div>&nbsp;<br/><tr><td><table width="358" border="1" align="center" cellpadding="0" cellspacing="2" bordercolor="#c4d6c4" bgcolor="#ffffff">
    <tr>
    <td width="358" height="26" colspan="2" background="images/main_bs.gif"><div align="center" style="font-size: 24px">
    <p class="STYLE2" style="font-weight: bold">学生基本情况查询</p>
    </div></td></tr>
    <tr>
    <td colspan="2" align="right">请注意:带有<span class="STYLE12">*</span>的项目必须填写。</td></tr>
    <form action="xsqkcx.asp?d=add" method="post">
    <tr><td width="25%" align="right">学生年级:&nbsp;</td><td><input type="text" name="xs_nj" size="12" />&nbsp;<span class="STYLE12">*</span></td></tr>
    <tr><td width="25%" align="right">学生专业:&nbsp;</td><td><input type="text" name="xs_zy" size="12" />&nbsp;<span class="STYLE12">*</span></td></tr>
    <tr><td width="25%" align="right">学生班级:&nbsp;</td><td><input type="text" name="xs_bj" size="12" />&nbsp;<span class="STYLE12">*</span></td></tr>
    <tr><td colspan="2" align="center"><input type="submit" value="查询">&nbsp;&nbsp;<input type="reset" value="重置"></td></tr>
    </form>
    </table>
    <div>&nbsp;<br/><br/></div></td></tr></tbody>
    <!-- #include file="eof.inc" -->
    <%end if%>
    请问一下,可以显示分几页,但点第二页是提示找不到记录,请问是什么原因
     
  2. Function

    Function New Member

    注册:
    2006-03-24
    帖子:
    3,884
    赞:
    5
    分页的时候,有传递这些参数吗?两个地方的查询语句都用到了这几个参数。
     
  3. nucgegeasp

    nucgegeasp New Member

    注册:
    2007-04-21
    帖子:
    10
    赞:
    0
    我没看到你的rs.move (Current_page-1)*MaxPerPage这句啊,你怎么实现的分页功能?
    想学习一下。
    这是我用的分页用的函数,可以直接存为page.asp,到用的时候<!--#include file="page.asp"-->
    直接调用函数就行了。你自己研究一下吧
    <%
    function ShowPpage(currentPage,MaxPerPage,totalPut,filename)
    dim totalPage
    if totalPut mod MaxPerPage=0 then
    totalPage=totalPut \ MaxPerPage
    else
    totalPage=totalPut \ MaxPerPage + 1
    end if
    if currentPage<2 then
    response.write "首页 上一页 "
    else
    response.write "<a href='"&filename&"?page=1'>首页</a> "
    response.write "<a href='"&filename&"?page="&currentPage-1&"'>上一页</a> "
    end if
    if totalPage-currentPage<1 then
    response.write "下一页 尾页 "
    else
    response.write "<a href='"&filename&"?page="&currentPage+1&"'>下一页</a> "
    response.write "<a href='"&filename&"?page="&totalPage&"'>尾页</a> "
    end if
    response.write " 共"&totalPut&"条 每页"&MaxPerPage&"条"
    end function
    %>
    <%
    Function ShowContent(currentPage,MaxPerPage,filename)
    Dim i
    for i=1 to MaxPerPage
    if rs.bof and rs.eof then
    exit for
    end if
    if currentPage=1 then
    %>
    <p><img src="top<%= i %>.gif" width="14" height="14">
     <a href="<%= filename %>?id=<%= rs("r_id") %>"><%= rs("r_title") %></a> <%= rs("r_title") %></p>
    <%
    else
    %>
    <p><%= i+(currentPage-1)*MaxPerPage %>.
     <a href="<%= filename %>?id=<%= rs("r_id") %>"><%= rs("r_title") %></a> <%= rs("r_title") %></p>
    <%
    end if
    rs.movenext
    next
    if rs.bof and rs.eof and i=1 then
    response.write "暂时还没有任何通知"
    end if
    End Function
    %>