<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>asp分页程序</title> <style type="text/css"> <!-- .STYLE1 {font-size: 12px} --> </style></head>
<body> <p> <table width="186" height="39" border="1" cellpadding="0" cellspacing="0"> <tr> <td>姓名</td> <td>密码</td> </tr> <% set rs=server.createobject("adodb.recordset") conn = "DBQ=" + server.mappath("zheng.mdb") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};" sql="select * from user"
rs.open sql,conn,1,2 rs.pagesize=6 '设置页面显示得页数 if request("page")<>"" then epage=cint(request("page")) if epage<1 then epage=1 if epage>rs.pagecount then epage=rs.pagecount else epage=1 end if rs.absolutepage=epage for i=0 to rs.pagesize-1 if rs.bof or rs.eof then exit for %><tr> <td><%=rs("name")%></td> <td><%=rs("pass")%></td> </tr>
<% rs.movenext next %> </table> <div align="left"><span class="STYLE1"> <form method="get" onsubmit=""document.location ="c.asp?Page='+ this.page.value;return false;'"> <%if epage=1 then response.Write("首页")else response.Write("<a href='c.asp?page=1'>"&"首页"&"</a>")%> <%if epage=1 then response.write("上一页")else response.write"<a href=c.asp?page="&epage-1&">上一页</a>"%> <%if epage = rs.pagecount then response.write("下一页")else response.write"<a href=c.asp?page="&epage+1&">下一页</a>"%> <%if epage = rs.pagecount then response.write("末页")else response.write"<a href=c.asp?page="&rs.pagecount&">末页</a>"%> 现在是第<font color="red"><%=epage%></font>页一共有<font color="red"><%=rs.pagecount%></font>页 <input name="page" value="<%=epage%>" maxlength=5 tyep=text /> 页 <input type=submit value=GO style="font-size:12px;border:1px solid #CCCCCC;width:23px;" /></form> </div> <p> </p> <p> <%
name=request("name") pass=request("pass") if name<>"" and pass<>"" then rs.Addnew rs("name")=name rs("pass")=pass rs.update rs.close end if %> </p> </p> <form id="form1" name="form1" method="post" action=""> <p> <input name="name" type="text" id="name" /> </p> <p> <input name="pass" type="text" id="pass" /> <input type="submit" name="Submit" value="提交" /> </p> </form> <p> <table width="63%" border="0" cellpadding="0" cellspacing="1" bgcolor="#0000FF" style="border-collapse: collapse"> <% set mrs=server.createobject("adodb.recordset") conn = "DBQ=" + server.mappath("zheng.mdb") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};" sql="select * from user"
mrs.open sql,conn,1,1 If mRs.bof and mRs.eof then Response.Write"<span>没有任何记录</span>" Response.End Else mRs.PageSize =6'每页记录条数 iCount=mRs.RecordCount '记录总数 iPageSize=mRs.PageSize maxpage=mRs.PageCount page=request("page")
If Not IsNumeric(page) or page="" then page=1 Else page=cint(page) End If If page<1 then page=1 ElseIf page>maxpage then page=maxpage End If mRs.AbsolutePage=Page If page=maxpage then x=iCount-(maxpage-1)*iPageSize Else x=iPageSize End If End If
for i=1 to mRs.pagesize
%> <tr> <td width="64%" bgcolor="#FFFFFF" class="STYLE1"><%=mrs("name")%></td> <td width="36%" bgcolor="#FFFFFF" class="STYLE1"><%=mrs("pass")%></td> </tr><% mRs.movenext If mRs.eof then exit for next mRs.close Set mRs=nothing %> <tr> <td colspan="2" bgcolor="#CCCCCC"> <span class="STYLE1"> <% call PageControl(iCount,maxpage,page) Sub PageControl(iCount,pagecount,page)
'生成上一页下一页链接 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("<table border='0' cellpadding='3' style='border-collapse: collapse' width='100%' align='center'>") Response.Write("<form method=get onsubmit=""document.location = '" & action & "?" & temp & "Page='+ this.page.value;return false;""><tr>") Response.Write("<td align='center' bgcolor='#FFFFFF'>") If page<=1 then Response.Write ("首页 " ) Response.Write ("上一页 ") Else Response.Write("<a href=" & action & "?" & temp & "Page=1>首页</a> ") Response.Write("<a href=" & action & "?" & temp & "Page=" & (Page-1) & ">上一页</a> ") End If If page>=pagecount then Response.Write ("下一页 ") Response.Write ("尾页 ") Else Response.Write("<a href=" & action & "?" & temp & "Page=" & (Page+1) & ">下一页</a> ") Response.Write("<a href=" & action & "?" & temp & "Page=" & pagecount & ">尾页</a> ") End If Response.Write(" 页次:" & page & "/" & pageCount & " 页") Response.Write(" 共有 " & iCount & " 条留言") Response.Write(" 转到 " & "<input tyep=text name=page maxlength=5 value=" & page & " style='font-size: 12px;border: 1px solid #CCCCCC;width:23px;'>" & " 页 <input type=submit style=""font-size: 9pt"" value=GO style='font-size: 12px;border: 1px solid #CCCCCC;width:23px;'>") Response.Write("</td></tr></form>") Response.Write("</table>")
End Sub %> </span></td> </tr> </table>
<span class="STYLE1"> </p>
</form> </body> </html>
|
请发表评论