asp 分頁函數(shù),可以顯示 1,2,3,4,5... 前十頁,后十頁,下一頁,上一頁 方法一:
<% SoFia_DbName="jiaoyou" '修改此處為你的SQL Server 數(shù)據(jù)庫名稱 YourServer = "seven" '修改此處為你的Sql Server數(shù)據(jù)庫地址 YourUid = "sa" '修改此處為你的數(shù)據(jù)庫用戶名 YourPassword = "struts" '修改此處為你的數(shù)據(jù)庫密碼 Connstr = "Driver={SQL Server};Server="&YourServer&";Uid="&YourUid&";Pwd="&YourPassword&";Database="&SoFia_DbName Set Conn=Server.CreateObject("ADODB.CONNECTION") ' On Error Resume Next Conn.Open Connstr If Err<>0 Then err.Clear Set Conn = Nothing Response.Write "<div align=center><br><br><br>連接SqlServer數(shù)據(jù)庫出錯(cuò),請(qǐng)檢查相關(guān)設(shè)置……</div>" Response.End End If
set rs = server.CreateObject("adodb.recordset") rs.open "select * from userInfo order by id desc",conn,1,1 if not(rs.Eof and rs.Bof) Then page = trim(request.form("page")) if page = "" then page = trim(request.QueryString("page")) if Not(IsNumeric(page)) or page = "0" then page = 1 rs.pageSize = 30 '設(shè)置每頁的個(gè)數(shù) strFile = "?" '設(shè)置當(dāng)前頁面的名稱 pageCount = rs.pageCount if len(page) > 4 then page = pageCount if Cint(page) > Cint(pageCount) then page = pageCount rs.absolutepage = page for i = 1 to rs.pagesize if rs.eof then exit for Response.Write (Rs("username")&"<br>")&VbNewline rs.MoveNext Next'i End if%>
<% Response.Write ("<table border=0 align=center cellpadding=0 cellspacing=0><tr><td>")&VbNewline if pagecount < 1 then pagecount = 1 response.Write ("第"&page&"頁/共"&PAGECOUNT&"頁,每頁"&rs.pageSize&"條/共"&rs.recordCount&"條記錄</td><td> ") beginpage = 1 endpage = CInt(pagecount) page = CInt(page) if pagecount >= 9 then if page >= 5 then beginpage = page - 4 if page <= (pagecount - 4) then endpage = page + 4 else endpage = pagecount beginpage = pagecount - 4 end if else beginpage = 1 endpage = 9 end if end if if beginpage>1 then response.write "<a title=首頁 href='"&strFile&logpage&"'><font face=webdings>9</font></a>" for j = beginpage to endpage if j = page then response.write"[<b>"&j&"</b>] " else response.write"[<a href='"&strFile&"page="&j&logpage&"'>"&j&"</a>] " end if next if endpage < pagecount then response.write ("<a title=末頁 href='"&strFile&"page="&pagecount&logpage&"'><font face=webdings>:</font></a>") Response.Write ("</td><form name='changepage' method='post' action='"&strFile&"'><td align='right'> ")&VbNewline Response.Write ("<select name='page' onchange='document.changepage.submit();'>")&VbNewline For i=0 To pagecount If i<>pagecount Then Response.Write ("<option value='"&i+1&"'") If page=i+1 Then Response.Write (" selected") Response.Write (">"&i+1&"</option>")&VbNewline End If Next Response.Write ("</select></td></form></tr></table>") rs.close set rs = nothing %>
方法二:
<!--#include file="conn.asp"--> <% dim ip ip=Request.ServerVariables("REMOTE_ADDR") %> <html>
<% set rs=server.createobject("adodb.recordset") sql="select * from info where used=0 and pn<>'0' order by pn" rs.open sql,conn,1,1 %> <table width="870" border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" class=text> <tr><td colspan="6"> 共有:<font size=2 color=red><b> <%=rs.recordcount%> </b></font><font size=2>個(gè)軟件</font> <% MMaxPerPage=15 rs.PageSize=MMaxPerPage if trim(request("Page"))<>"" then CurrentPage=CInt(request("Page")) if CurrentPage>rs.PageCount then CurrentPage=rs.PageCount end if else CurrentPage=1 end if
ttotalPut=rs.RecordCount if CurrentPage<>1 then if (CurrentPage-1)*MMaxPerPage<ttotalPut then rs.Move(CurrentPage-1)*MMaxPerPage bookmark=rs.Bookmark end if end if
if (ttotalPut mod MMaxPerPage)=0 then mm=ttotalPut\MMaxPerPage else mm=ttotalPut\MMaxPerPage+1 end if
if (ttotalPut mod (MMaxPerPage*10))=0 then nn=ttotalPut\(MMaxPerPage*10) else nn=ttotalPut\(MMaxPerPage*10)+1 end if %>
<% if (CurrentPage mod 10)=0 then kk=CurrentPage\10-1 else kk=CurrentPage\10 end if
if nn>1 and CurrentPage>10 then Response.Write "<b><a href='all.asp?s1="&request("s1")&"&s2="&request("s2")&"&s3="&request("s3")&"&s4="&request("s4")&"&andor="&request("andor")&"&ss="&request("ss")&"&page="+CStr((kk-1)*10+1)+"'>Pre.</a></b>" end if
for ii=1 to 10 jj=kk*10+ii if jj<=mm then if jj=CurrentPage then Response.Write " <font color=red>"+CStr(jj)+"</font>" else Response.Write " <b>"+"<a href='all.asp?s1="&request("s1")&"&s2="&request("s2")&"&s3="&request("s3")&"&s4="&request("s4")&"&andor="&request("andor")&"&ss="&request("ss")&"&page="+CStr(jj)+"'>"+CStr(jj)+"</a></b>" end if end if next
Response.Write " " if kk<nn-1 then Response.Write " <b>"+"<a href='all.asp?s1="&request("s1")&"&s2="&request("s2")&"&s3="&request("s3")&"&s4="&request("s4")&"&andor="&request("andor")&"&ss="&request("ss")&"&page="+CStr((kk+1)*10+1)+"'>Next</a></b>"