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

ASP+ACCESS分页有关问题

2012-04-17 
ASP+ACCESS分页问题现在的状况是不报错,但是每次点击下一页,总是显示第一页的数据,请各位大侠帮忙看看谢谢

ASP+ACCESS分页问题
现在的状况是不报错,但是每次点击下一页,总是显示第一页的数据,请各位大侠帮忙看看   谢谢

<%@LANGUAGE= "VBSCRIPT "   CODEPAGE= "936 "%>
<%
If   Session( "UserName ")   =   " "   Then
    Response.Redirect   "login.htm "
End   If
%>
<HTML>
<HEAD>
<TITLE> 查询资料 </TITLE>
<STYLE>
P,   TABLE,   SELECT,   INPUT{FONT-SIZE:   9pt}
.style2   {color:   #003366}
.style3   {color:   #FFFFFF}
</STYLE>
</HEAD>
<BODY>
<div   align= "center ">
    <%
Response.Buffer   =   True  
Response.ExpiresAbsolute   =   Now()   -   1  
Response.Expires   =   0  
Response.CacheControl   =   "no-cache "  
Response.AddHeader   "Pragma ",   "No-Cache "
%>
    <!-- <img   src= "image/logo.gif "   width= "500 "   height= "200 "> -->
</div>
<!--   #include     file= "inc\adovbs.inc "   -->
<DIV   ALIGN   =   "center ">
<FORM   NAME   =   "Form1 "   METHOD   =   "post "   ACTION   =   "browseInfo.asp ">
    <table   width= "100% "   border= "0 ">
    <tr>
        <td   width= "700 "   bgcolor= "#003399 "> <div   align= "center "   class= "style3 ">
            <div   align= "right "> 查询:
                            <select   size   =   "1 "   name   =   "lstFld ">
                                <option   selected   value   =   "all "       > 全部显示                         </option>
                                <option   value   =   "num "                         > 编号                                 </option>
                            </select>
            值:
            <input   name   =   "txtValue "   type   =   "text "   size   =   "20 ">
&nbsp;&nbsp;
    <input   name   =   "btnSubmit "   type   =   "submit "   value   =   "查询 ">
            </div>
        </div> </td>
    </tr>
</table>
</FORM>
<%
Dim   cnn,   rst,   sSQL,   currentPage,   rowCount,   i


If   Request.Form( "btnSubmit ")   =   " "   Then
    Response.End
End   If  
currentPage   =   Request.QueryString( "currentPage ")
If   currentPage   =   " "   Then
    currentPage   =   1
End   If
Set   cnn   =   Server.CreateObject( "ADODB.Connection ")
Set   rst   =   Server.CreateObject( "ADODB.Recordset ")
cnn.ConnectionString   =   "PROVIDER=microsoft.jet.oledb.4.0;DATA   SOURCE= "   &   server.mappath( "Date\date.mdb ")
cnn.Open
rst.CursorType   =   adOpenStatic
rst.PageSize   =   1
Field   =   Request.Form( "lstFld ")
Value   =   Trim(Request.Form( "txtValue "))
If   Field   =   "all "   Then
    sSQL   =   "SELECT   *   FROM   Dr   ORDER   BY   ID "
End   If
If   Field   <>   "all "   And   Value   <>   " "   Then
    sSQL   =   "SELECT   *   FROM   Dr   WHERE   "   &   Field   &   "   like   '% "   &   Value   &   "% '   ORDER   BY   ID "
End   If
rst.Open   sSQL,   cnn
If   rst.EOF   Then
    Response.Write   " <P> <FONT   COLOR   =   red> 没有找到符合条件的记录! </FONT> </P> "
Else
rowCount   =   0  
%>
<TABLE   BORDER   =   "1 "   cellpadding= "2 "   cellspacing= "1 "   bordercolor= "#003399 ">
<tr   bgcolor= "#003399 "> <th   colspan= "4 "   class= "style3 "> <B> 查询结果: </B> 共 <%   =   rst.RecordCount   %> 人 </th> </tr>
<TR   bgcolor= "#CCCCCC ">
<TH> <span   class= "style2 "> 编号 </span> </TH>

</TR>
<%   While   Not   rst.EOF   And   rowCount   <   rst.PageSize   %>
<TR>
<TD>
<%   =   rst( "num ")   %>
</TD>
</TR>
<%
rowCount   =   rowCount   +   1
rst.MoveNext
Wend
%>
</TABLE>
<P>
每页 <%   =   rst.PageSize   %> 个人&nbsp;当前页次: <%   =   currentPage   %> / <%   =   rst.PageCount   %> 页&nbsp;
<%   For   i   =   1   To   rst.PageCount
If   i   =   CInt(currentPage)   Then   %> [ <FONT   COLOR   =   "red "> <%=   i   %> </FONT> ]&nbsp;&nbsp;
<%   Else   %>
[ <A   HREF   =   "browseInfo.asp?currentPage= <%=   i   %> "> <%=   i   %> </A> ]&nbsp;&nbsp;
<%  
End   If
Next
End   If
%>
</P> </DIV>
</BODY>
<%
            rst.close
            set   rst=nothing
            cnn.close
            set   cnn=nothing


%>
</HTML>

[解决办法]
我给你发一个今天我才弄完的全代码吧,有标注你自己看下吧:
======================================================
<%dim keyword
keyword=request.QueryString( "keyword ")
if keyword= " " then
response.write " <script> alert( " "关键字不能为空,请勿用其它途径访问本站! " ");location.href= " "./ " "; </script> "
response.end
end if%>
<a href= "/ "> 首页 </a> &gt; 信息搜索
&gt; 关键字: <span class= "style9 "> <%=keyword%>
<%
dim MaxPerPage
dim sql
dim rs
dim gstBookID
dim totalPut
dim CurrentPage
dim TotalPages
if not isempty(request( "page ")) then
currentPage=cint(request( "page "))
else
currentPage=1
end if
set rs=server.CreateObject( "adodb.recordset ")
sql= "select * From [表名称] where [字段A] like '% "&keyword& "% ' "
rs.open sql,conn,1,1
if rs.eof And rs.bof then
Response.Write " <br> <p align=center> 对不起,没有找到相关信息 </p> <br> "
else
rs.pagesize=80 '显示条数
totalPut=rs.recordcount '记录总数
totalPage=rs.pagecount
MaxPerPage=rs.pagesize
if currentpage <1 then
currentpage=1
end if
if currentpage> totalPage then
currentpage=totalPage
end if
if currentPage=1 then
showpages
showContent
else
if (currentPage-1)*MaxPerPage <totalPut then
rs.move (currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark '移动到开始显示的记录位置
showpages
showContent
else
end if
end if
end if
rs.close
set rs=nothing
conn.close
set conn=nothing
sub showContent
dim i,j
i=1
do while not (rs.eof or err)%>
'读取你显示的字段
<%=rs( "字段1 ")%>
<%=rs( "字段2 ")%>
......
<%
if i> =MaxPerPage then exit do '循环时如果到尾部则先退出,如果记录达到页最大显示数,也退出
i=i+1
rs.movenext
loop
end sub
sub showpages()
end sub
dim n
n=totalPage
%>
<div align= "center ">
<table border= "0 " width= "100% " cellspacing= "0 " cellpadding= "0 " id= "table2 " height= "33 ">
<form action= "?keyword= <%=keyword%> " method= "GET "> <tr>
<td>
 检索到目前共有 <font color= "#FF0000 "> <%=totalPage%> </font> 页/ <font color= "#FF0000 "> <%=totalPut%> </font> 条信息
<% If currentPage <> 1 Then %> <a href= "?keyword= <%=keyword%> "> [首页] </a>
<a href= "?keyword= <%=keyword%> &Page= <%= (currentPage-1) %> "> [上一页] </a>
<% End If %>
<% If currentPage <> totalPage Then %> <a href= "?keyword= <%=keyword%> &Page= <%= (currentPage+1) %> ">
[下一页] </a>
<a href= "?keyword= <%=keyword%> &Page= <%= totalPage %> "> [尾页] </a>
<% End If %>
第 <font color= "#FF0000 "> <%=currentPage%> </font> 页/共 <font color= "#FF0000 "> <%=totalPage%> </font> 页


<% response.write " 转到: <select name= 'page 'class=smallselsect '> "

for i=1 to n
response.write " <option value= "& i
if currentpage=i then
response.write " selected "
end if
response.write "> "& i & " </option> "
next
response.write " </select> "
response.write "&nbsp; <input class=buttonface type= 'submit ' value= 'GO '> "
%>
</td>
</tr>
</form> </table>
[解决办法]
<%
Dim MyPageSize,MyPage
Page=CInt(Request.QueryString( "Page "))
MyPageSize = 20 '每页显示
If Not IsNumeric(Page) Or IsEmpty(Page) Or Page <=0 Then
MyPage=1
else
MyPage=Abs(Page)
end if
set rs=server.CreateObject( "ADODB.RecordSet ")
Sql= "select * from [Table] where id= "&id& " "
rs.Open sql,conn,1,1
if not rs.eof then
rs.PageSize = MyPageSize
MaxPages = rs.PageCount
Total = rs.RecordCount
rs.absolutepage = MyPage
end if
dim i
Counter=0
for i = 1 to MyPageSize
if not rs.eof then
%>
<a href= 'NewsLook.asp?id= <%=rs( "id ")%> '> <%=rs( "title ")%> </a> '循环显示数据
<%
else
exit for
end if
rs.movenext
Next
%>
'以下代码不需要做任何改动
<%
Dim query, a, x, temp
action = "http:// " & Request.ServerVariables( "HTTP_HOST ") & Request.ServerVariables( "SCRIPT_NAME ")
query = Split(Request.ServerVariables( "QUERY_STRING "), "& ")
For Each x In query
a = Split(x, "= ")
If StrComp(a(0), "page ", vbTextCompare) <> 0 Then
temp = temp & a(0) & "= " & a(1) & "& "
End If
Next
response.Write( " <div align=center> ")
response.Write( "[ <a href= " " " & action & "? " & temp & "page=1 " " title= " "第一页 " "> < < </a> ] ")
if MyPage > 1 then
response.Write( "[ <a href= " " " & action & "? " & temp & "page= "&MyPage-1& " " " title= " "上一页 " "> < </a> ] ")
end if
if (MyPage > = 5 and MaxPages-MyPage <1) then response.Write( "[ <a href= " " " & action & "? " & temp & "page= "&MyPage-4& " " "> "&MyPage-4& " </a> ] ")
if (MyPage > = 4 and MaxPages-MyPage <2) then response.Write( "[ <a href= " " " & action & "? " & temp & "page= "&MyPage-3& " " "> "&MyPage-3& " </a> ] ")
if MyPage > =3 then response.Write( " <a href= " " " & action & "? " & temp & "page= "&MyPage-2& " " "> [ "&MyPage-2& "] </a> ")
if MyPage > =2 then response.Write( " <a href= " " " & action & "? " & temp & "page= "&MyPage-1& " " "> [ "&MyPage-1& "] </a> ")


response.Write( "[ <font color=#cc0000> "&MyPage& " </font> ] ")
if MaxPages-MyPage > =1 then response.Write( "[ <a href= " " " & action & "? " & temp & "page= "&MyPage+1& " " "> "&MyPage+1& " </a> ] ")
if MaxPages-MyPage > =2 then response.Write( "[ <a href= " " " & action & "? " & temp & "page= "&MyPage+2& " " "> "&MyPage+2& " </a> ] ")
if (MyPage <3 and MaxPages-MyPage > =3) then response.Write( "[ <a href= " " " & action & "? " & temp & "page= "&MyPage+3& " " "> "&MyPage+3& " </a> ] ")
if (MyPage <2 and MaxPages-MyPage > =4) then response.Write( "[ <a href= " " " & action & "? " & temp & "page= "&MyPage+4& " " "> "&MyPage+4& " </a> ] ")
if (MyPage <1 and MaxPages-MyPage > =5) then response.Write( "[ <a href= " " " & action & "? " & temp & "page= "&MyPage+5& " " "> "&MyPage+5& " </a> ] ")
if MyPage < MaxPages then
response.Write( "[ <a href= " " " & action & "? " & temp & "page= "&MyPage+1& " " " title= " "下一页 " "> > </a> ] ")
end if
response.Write( "[ <a href= " " " & action & "? " & temp & "page= "&MaxPages& " " " title= " "最后页 " "> > > </a> ] ")
response.Write( "&nbsp;pages: [ <font color= " "#CC0000 " "> <b> "&MyPage& " </b> </font> / <b> "&MaxPages& " </b> ] &nbsp;total [ <b> "&Total& " </b> ] items&nbsp; [ <b> "&MyPageSize& " </b> ] Items in this page ")
response.Write( " </div> ")
%>

此分页代码可以实现: 首页 上一页 [1][2][3][4][5][6][7][8][9][10] 后一页 尾页 分页功能
测试成功记得给分哈

热点排行