asp分页代码
ASP
2025-01-05 09:40
78
0
<% 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>