asp分頁(自己整理的2個分頁程式)

來源:互聯網
上載者:User

<%@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>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.