① asp如何分頁
<%
dim rs,strsql
set rs=server.CreateObject("ADODB.recordset")
strsql="select * from users where level=0 order by id desc"
rs.open strsql,conn,1,1
IF Rs.Recordcount>0 Then
Rs.PageSize=20'每頁最多顯示多少條記錄
Page=Clng(Request.QueryString("Page"))
IF Page>Rs.PageCount Then Page=Rs.PageCount
IF Page<1 Then Page=1
Rs.Absolutepage=Page
For i=1 To Rs.PageCount
%>
<tr><td>
<%=rs("name")%>
</td><td>
<%=rs("school")%>
</td><td>
<%=rs("tel")%>
</td></tr>
<%
rs.movenext
IF Rs.Eof Then Exit For
Next
%>
<tr><td colspan="3">當前頁碼<%=Page&"/"&Rs.PageCount%> <a href="?Page=1">首頁</a> <a href="?Page=<%=Page-1%>">上一頁</a> <a href="?Page=<%=Page+1%>">下一頁</a> <a href="?Page=<%=Rs.PageCount%>">尾頁</a></td></tr>
② ASP中記錄集如何分頁
雖然可以用記錄集的 PageSize(每頁記錄數)、PageCount(總頁數)和AbsolutePage(當前頁碼)三個屬性來分頁,但是不推薦這么做。
我通常是把所有ID抓下來進行手工分頁,再根據需要讀取當前頁所有記錄。
③ 一個關於ASP資料庫分頁的問題請教
是這樣的,你的每頁都循環寫出20條記錄
前兩頁都是正確的因為他們都滿足夠20條記錄這個條件,所以指針不會跑出記錄之外
而第三頁不足20條,所以當它到第十六條記錄時,就會跑出記錄之外
而這時,當指針在記錄之外,卻要引用記錄集某個欄位時,就會出錯
系統報錯,就會出現什麼eof,bof之類的
解決方法
在每次操作數據時都要加上一個驗證語句,如我這樣寫
for i=1 to rs.reocrdcount
if not rs.bof and not rs.eof then
'讀出數據
else
exit for
end if
next
明白我的意思了嗎?
④ asp怎麼分頁顯示啊
作為一個程序員詳細代碼你還是自己寫吧,這里只給個思路:分頁的原理就是每次點擊下一頁的時候url中傳遞一個頁面的變數到ASP頁面,這個ASP頁面在哪用到這個變數呢?就是在SELECT語句中用到的,比如說你每次從資料庫中取10條記錄(相當於設置每頁顯示10條),那個變數就是取記錄的起始位置,大體就是這樣了,具體代碼中你要先算出總共記錄條數,你想每頁顯示多少條,從而再算出總共多少頁
⑤ 如何實現ASP分頁功能
我來試試看:
<!--#include file="conn.asp"-->
<%
set rsc=server.createobject("adodb.recordset")
sqlc="select * from news where class='"&rs("class")&"' order by id desc"
rsc.open sqlc,conn,1,1
Response.write "<center>"
rsc.PageSize = 10 'pagesize屬性指定了每頁要顯示的記錄條數
Page = CLng(Request("Page")) 』string型轉化為long型
If Page < 1 Then Page = 1
If Page > rsc.PageCount Then Page = rsc.PageCount
If Page <> 1 Then
Response.Write "<A HREF=emp1.asp?Page=1>第一頁</A>�"
Response.Write "<A HREF=emp1.asp?Page=" & (Page-1) & ">上一頁</A>�"
End If
If Page <> rsc.PageCount Then
Response.Write "<A HREF=emp1.asp?Page=" & (Page+1) & ">下一頁</A>�"
Response.Write "<A HREF=emp1.asp?Page="& rsc.PageCount & ">最後一頁</A>�"
End If
Response.write "頁碼:" & Page & "/" & rsc.PageCount & "</center><table border=1>"
rsc.AbsolutePage = Page '把頁碼賦給absolutepage屬性從而知當前頁的首條記錄號
For iPage = 1 To rsc.PageSize
%>
<tr>
<td width="574" bordercolor="#CCCCCC" class="classlist"><div align="left" class="classlist"><span class="classlist"><a href="news.asp?id=<%=rsc("id")%>"><%=rsc("title")%></a></span></div></td>
<td width="196" height="16" bordercolor="#CCCCCC" ><%=rsc("time")%></td>
<td width="112" height="16" bordercolor="#CCCCCC" ><%=rsc("by")%></td>
<%
rsc.MoveNext
If rsc.EOF Then Exit For
Next
%>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
<br />
<table width="100%" border="1" bordercolor="#FFFFFF">
<tr>
<td width="100%" bordercolor="#CCCCCC">
td>
</tr>
</table>
</div>
</body>
</html>
<%
rs.close
rsc.close
set rs=nothing
set rsc=nothing
conn.close
set conn=nothing
%>
⑥ asp中關於分頁設置的問題(尤其是首頁和最後一頁)怎麼在伺服器行為中設置
完整分頁代碼:
<%
set rs=server.createobject("adodb.recordset")
sql="select * from [news] where cp_type='新聞中心' order by uptime desc"
rs.open sql,conn,1,1
if not rs.eof then
rs.pagesize=10 '定義一頁顯示的記錄數目
tatalrecord=rs.recordcount '獲取記錄總數目
tatalpages=rs.pagecount '獲取分頁的數目
nowpage=request("page") '用request獲取當前頁數,注意page是自己定義的變數並非函數
if nowpage&"x"="x" then '處理頁碼為空時的情況
nowpage=1
else
nowpage=cint(nowpage) '將頁碼轉換成數字型
end if
rs.absolutepage=nowpage '將指針移動到當前顯示頁的第一條記錄'
n=0
%>
<div align="right">共:<%=tatalpages%>頁 當前為:<%=nowpage%>頁
<%if nowpage>1 then%>
<a href="?page=<%=nowpage-1%>" class="yangshi1">上一頁</a>
<%else%>
上一頁
<%end if%>
<%for k=1 to tatalpages%>
<%if k<>nowpage then %>
<a href="?page=<%=k%>" class="yangshi1"><%=k%></a>
<%else%>
<%=k%>
<%end if%>
<%next%>
<%if nowpage < tatalpages then%>
<a href="?page=<%=nowpage+1%>" class="yangshi1">下一頁</a>
<%else%>
下一頁
<%end if%>
<%if nowpage<>1 then%>
<a href="?page=<%=1%>" class="yangshi1">首頁</a>
<%else%>
首頁
<%end if%>
<%if nowpage<>tatalpages then %>
<a href="?page=<%=tatalpages%>" class="yangshi1">末頁</a>
<%else%>
末頁
<%end if%>
</div>
⑦ ASP中怎麼分頁顯示資料庫里的數據
Sub show()
logusername = replace(trim(request.Querystring("logusername")),"'","")
if logusername <> "" then
sql="select * from JB_log where username='"+ logusername +"' order by logid desc"
logpage = "&logusername="& logusername
logtext = "當前顯示<font color=red>"& logusername &"</font>的操作日誌 | <a href=""logs.asp"">顯示全部</a>"
else
sql="select * from JB_log order by logid desc"
End if
set rs = server.CreateObject("adodb.recordset")
rs.open sql,conn,1,1
%>
<table height="29" border="0" align="center" cellpadding="0" cellspacing="0" class="table-noColor">
<form name="form2" method="Get" action="logs.asp"><tr>
<td>輸入操作人:
<input name="logusername" type="text" id="logusername" size="16" maxlength="20">
<input type="submit" name="Submit3" value="搜索"><%=logtext%>
</td>
</tr></form>
</table>
<table border="0" align="center" cellpadding="3" cellspacing="1" class="table">
<form name="form4" method="post" action="logs.asp?action=del"><tr>
<td class="table-title">操作人</td>
<td class="table-title">操作時間</td>
<td class="table-title"> 操作內容/文章作者</td>
<td class="table-title">操作理由/扣分</td>
<td class="table-title" align="center">內容</td>
<td class="table-title">操作時IP</td>
<%
if userID=33 and usergroup=1 then
%>
<td width="15" class="table-title">
</td>
<%
end if
%>
</tr>
<%
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 = 60
pageCount = rs.pageCount
if len(page) > 4 then page = pageCount
if Cint(page) > Cint(pageCount) then page = pageCount
rs.absolutepage = page
color2 = 0
for i = 1 to rs.pagesize
if rs.eof then exit for
if color2 mod 2 = 0 then
color1 = "Class=""table-dark"""
else
color1 = "Class=""table-light"""
end if
%>
<tr <%=color1%>>
<td><%="<a href=""user.asp?userid="&rtrim(rs("userid"))&""" target=""_blank"">"&rtrim(rs("username"))&"</a>"%></td>
<td><%=rtrim(rs("logtime"))%></td>
<td><%=rtrim(rs("logC"))%></td>
<td><%=rtrim(rs("reason"))%></td>
<td align="center"><a href="?action=showlog&logid=<%=rs("logid")%>">
<%if trim(rs("oldcontent")) <> "" then response.Write("查看") end if%>
</a></td>
<td><%=rtrim(rs("logIP"))%></td>
<%
if userID=33 and usergroup=1 then
%>
<td align="center">
<input name="logid" type="checkbox" id="logid" value="<%=trim(rs("logid"))%>">
</td>
<%
End if
%>
</tr>
<%
rs.MoveNext
color2=color2+1
Next'i
End if
if userID=33 and usergroup=1 then
%>
<tr align="right" <%=color1%>>
<script language="javascript">
function AllSet(theForm)
{
for(i=0;i<document.form4.length;i++)
if(document.form4.elements[i].type=="checkbox")
document.form4.elements[i].checked=1}
function Reverse()
{
for(i=0;i<document.form4.length;i++)
if(document.form4.elements[i].type=="checkbox")
if(document.form4.elements[i].checked==1)
document.form4.elements[i].checked=0
else
document.form4.elements[i].checked=1}
function ReSet()
{
for(i=0;i<document.form4.length;i++)
if(document.form4.elements[i].type=="checkbox")
if(document.form4.elements[i].checked==1)
document.form4.elements[i].checked=0}
</script>
<td colspan="7">
<input name="button" type=button onclick="AllSet()" value="全選">
<input name="button" type=button onclick="Reverse()" value="反選">
<input name="button" type=button onclick="ReSet()" value="不選">
<input name="Submit" type="submit" id="Submit" value="刪除所選"></td>
</tr>
<%
End if
%>
</form>
</table>
<table border="0" align="center" cellpadding="0" cellspacing="0" class="table-noColor">
<tr>
<td>
<%
if pagecount < 1 then pagecount = 1
response.Write "頁次:"& PAGECOUNT &"/" & page &"頁 每頁"& rs.pageSize &" 記錄"&rs.recordCount&" "
%>
</td>
<td height="30">分頁:
<%
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=""logs.asp?"& 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=""logs.asp?page=" & j & logpage &""">[" & j & "]</a>"
end if
next
if endpage < pagecount then response.write "<a title=""最末頁"" href=""logs.asp?page="& pagecount & logpage &"""><font face=webdings>:</font></a>"
%>
</td>
<form name="form1" method="post" action="">
<td align="right">轉到:第
<input name="page" type="text" size="3" maxlength="5">
<input type="submit" name="Submit2" value="頁">
</td>
</form>
</tr>
</table>
<%
rs.close
set rs = nothing
End Sub
⑧ 如何用asp的數據集實現分頁效果啊
ASP項目中的公共翻頁模塊
<%
'+++++++++++++++++++++++++++++++++++++
'◆模塊名稱: 公共翻頁模塊
'◆文 件 名: TurnPage.asp
'◆傳入參數: Rs_tmp (記錄集), PageSize (每頁顯示的記錄條數)
'◆輸 出: 記錄集翻頁顯示功能
'+++++++++++++++++++++++++++++++++++++
'
Sub TurnPage(ByRef Rs_tmp,PageSize) 'Rs_tmp 記錄集 ; PageSize 每頁顯示的記錄條數;
Dim TotalPage '總頁數
Dim PageNo '當前顯示的是第幾頁
Dim RecordCount '總記錄條數
Rs_tmp.PageSize = PageSize
RecordCount = Rs_tmp.RecordCount
TotalPage = INT(RecordCount / PageSize * -1)*-1
PageNo = Request.QueryString ("PageNo")
'直接輸入頁數跳轉;
If Request.Form("PageNo")<>"" Then PageNo = Request.Form("PageNo")
'如果沒有選擇第幾頁,則默認顯示第一頁;
If PageNo = "" then PageNo = 1
If RecordCount <> 0 then
Rs_tmp.AbsolutePage = PageNo
End If
'獲取當前文件名,使得每次翻頁都在當前頁面進行;
Dim fileName,postion
fileName = Request.ServerVariables("script_name")
postion = InstrRev(fileName,"/")+1
'取得當前的文件名稱,使翻頁的鏈接指向當前文件;
fileName = Mid(fileName,postion)
%>
<table border=0 width='100%'>
<tr>
<td align=left> 總頁數:<font color=#ff3333><%=TotalPage%></font>頁
當前第<font color=#ff3333><%=PageNo%></font>頁</td>
<td align="right">
<%If RecordCount = 0 or TotalPage = 1 Then
Response.Write "首頁|前頁|後頁|末頁"
Else%>
<a href="<%=fileName%>?PageNo=1">首頁|</a>
<%If PageNo - 1 = 0 Then
Response.Write "前頁|"
Else%>
<a href="<%=fileName%>?PageNo=<%=PageNo-1%>">前頁|</a>
<%End If
If PageNo+1 > TotalPage Then
Response.Write "後頁|"
Else%>
<a href="<%=fileName%>?PageNo=<%=PageNo+1%>">後頁|</a>
<%End If%>
<a href="<%=fileName%>?PageNo=<%=TotalPage%>">末頁</a>
<%End If%></td>
<td width=95>轉到第
<%If TotalPage = 1 Then%>
<input type=text name=PageNo size=3 readonly disabled style="background:#d3d3d3">
<%Else%>
<input type=text name=PageNo size=3 value="" title=請輸入頁號,然後回車>
<%End If%>頁
</td>
</tr>
</table>
<%End Sub%>
當然,大家可以把翻頁的鏈接做成圖片按鈕,這樣的話也面就更加美觀了。
調用方法:
1、在程序開始或要使用翻頁的地方包含翻頁模塊文件;
2、定義變數:RowCount,每頁顯示的記錄條數
3、調用翻頁過程:Call TurnPage(記錄集,RowCount)
4、在Do While 循環輸出記錄集的條件中加上" RowCount > 0 " 條件
5、在循環結束 "Loop前" 加上: RowCount = RowCount - 1
'-----------------------------------------------------
調用範例:
文件名:News.asp
<%
Dim Conn,Rs_News
Set Conn = server.CreateObject("ADODB.CONNECTION")
Conn.Open "cpm","cpm","cpm"
Dim Sql
Sql = "Select * from News"
Set Rs_News = Server.CreateObject("ADODB.RECORDSET")
Rs_News.Open Sql,Conn,1,3 '獲取的記錄集
'公共翻頁模塊開始%>
<!--#include file=../Public/TurnPage.asp-->
<%
Dim RowCount
RowCount = 10 '每頁顯示的記錄條數
Call TurnPage(Rs_News,RowCount)
'公共翻頁模塊結束%>
<table width=100%>
<tr>
<td>新聞編號</td>
<td>新聞標題</td>
<td>發布日期</td>
<tr>
<%
If Not Rs_News.eof
Do while Not Rs_News.eof and RowCount>0
%>
<tr>
<td><%=Rs_News("ID")%></td>
<td><%=Rs_News("Name")%></td>
<td><%=Rs_News("Date")%></td>
<tr>
<%
RowCount = RowCount - 1
Rs_News.MoveNext
Loop
End If
%>
⑨ asp如何分頁顯示
<% Response.Buffer=False %>
<%
Dim connstr
set bb = server.CreateObject("ADODB.Connection")
bb.open"driver=driver do microsoft access (*.mdb);uid=;pwd=;dbq="&server.MapPath("mychanpin.mdb")
%>
<html>
<head>
<title>每日銷售情況</title>
</head>
<body>
<% '=============分頁定義開始,可放在資料庫打開前或後
dim action
action=request.QueryString("action")
Const MaxPerPage=20 '定義每頁顯示記錄數,可根據實際自定義
dim totalPut
dim CurrentPage
dim TotalPages
dim j
dim sql
if Not isempty(request("page")) then
currentPage=Cint(request("page"))
else
currentPage=1
end if '=============分頁定義結束
%>
<%
set rs = server.CreateObject ("adodb.recordset")
sql="select * from changpin"
rs.open sql,bb,1,1
%>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center">序號</div></td>
<td><div align="center">日期</div></td>
<td><div align="center">已售</div></td>
</tr>
<%
'=============分頁類代碼開始,需放在資料庫數據表打開後
if err.number<>0 then
response.write "<p></p><p align='center'>資料庫中暫時無數據!</p><p></p>"
end if
if rs.eof And rs.bof then
Response.Write "<p></p><p align='center'>對不起,沒有符合條件記錄!</p><p></p>"
else
totalPut=rs.recordcount
if currentpage<1 then
currentpage=1
end if
if (currentpage-1)*MaxPerPage>totalput then
if (totalPut mod MaxPerPage)=0 then
currentpage= totalPut \ MaxPerPage
else
currentpage= totalPut \ MaxPerPage + 1
end if
end if
if currentPage=1 then
showContent
showpage totalput,MaxPerPage,""&request.ServerVariables("script_name")&""
else
if (currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
showContent
showpage totalput,MaxPerPage,""&request.ServerVariables("script_name")&""
else
currentPage=1
showContent
showpage totalput,MaxPerPage,""&request.ServerVariables("script_name")&""
end if
end if
end if '=============分頁類代碼結束onmouseover="this.background=' /images/999999.jpg'" onmouseout="this.background=' /images/1w.jpg'"
%>
<% '=============循環體開始
sub showContent
dim i
i=0
i=1
do while not rs.eof
%>
<tr>
<td><div align="center"><%=rs("ID")%></div></td>
<td><div align="center"><%=rs("data")%></div></td>
<td><div align="center"><%=rs("yishou")%></div></td>
</tr>
<%
i=i+1
if i>=MaxPerPage then Exit Do
rs.movenext
loop
%>
</table>
<%'=============放置分頁顯示開始
rs.close '釋放資源
set rs=nothing
End Sub '=============循環體結束
Function showpage(totalnumber,maxperpage,filename)
Dim n
If totalnumber Mod maxperpage=0 Then
n= totalnumber \ maxperpage
Else
n= totalnumber \ maxperpage+1
End If %>
<form method=Post action=<%=filename%>>
<p align="center" class="STYLE13">
<%If CurrentPage<2 Then %>
第一頁 上一頁
<% Else %>
<a href=<% = filename %>?cx=<% =s %>&page=1>第一頁</a>
<a href=<% = filename %>?cx=<% =s %>&page=<% = CurrentPage-1 %>>上一頁</a>
<% End If
If n-currentpage<1 Then %>
下一頁 尾 頁
<% Else %>
<a href=<% = filename %>?cx=<% =s %>&page=<% = (CurrentPage+1) %>>下一頁</a>
<a href=<% = filename %>?cx=<% =s %>&page=<% = n %>>尾 頁</a>
<% End If %>
頁次:<b><font color=red>
<% = CurrentPage %>
</font></b>/<b><% = n %></b>頁 <b><%=maxperpage%></b>個記錄/頁 共<b><%=totalnumber %></b>個記錄
轉到:<select name="cndok" class="STYLE15" onChange="javascript:location=this.options[this.selectedIndex].value;">
<%
for i = 1 to n
if i = CurrentPage then %>
<option value="<% = filename %>?cx=<% =s %>&page=<%=i%>" selected>第<%=i%>頁</option>
<%else%>
<option value="<% = filename %>?cx=<% =s %>&page=<%=i%>">第<%=i%>頁</option>
<%
end if
next
%>
</select></font>
</form></td>
</tr>
</table>
<% End Function '=============放置分頁顯示結束%>
</body>
</html>
⑩ 求asp大數據時的分頁代碼
<% sql = "select……………………省略了sql語句
Set rs=Server.Createobject("ADODB.RECORDSET")
rs.Open sql, conn, 1, 1
if not rs.eof then
pages = 30 』定義每頁顯示的記錄數
rs.pageSize = pages 』定義每頁顯示的記錄數
allPages = rs.pageCount』計算一共能分多少頁
page = Request.QueryString("page")』通過瀏覽器傳遞的頁數
』if語句屬於基本的排錯處理
if isEmpty(page) or Cint(page) < 1 then
page = 1
elseif Cint(page) > allPages then
page = allPages
end if
rs.AbsolutePage = page
Do while not rs.eof and pages > 0 %>
這里輸出你要的內容………………
<% pages = pages - 1
rs.MoveNext
Loop
else
Response.Write("資料庫暫無內容!")
End if
rs.Close
Set rs = Nothing %>
我用過好多次了,無限好用!