求具有翻页功能的原码

jlcbj_cn 2003-10-20 12:21:04
哪位高人能提供一下具有显示数据库查询结果的具有翻页功能的代码,最好前面有checkbox可以进行删除操作
...全文
84 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wjhcjg 2003-10-20
  • 打赏
  • 举报
回复
作一个翻页函数,以后每页只要在需要的地方调用就可以了,函数和调用例子如下面:
<%
'+++++++++++++++++++++++++++++++++++++
'◆模块名称: 公共翻页模块
'◆文 件 名: TurnPage.asp
'◆传入参数: Rs (记录集), PageSize (每页显示的记录条数)
'◆输 出: 记录集翻页显示功能
'+++++++++++++++++++++++++++++++++++++
'
Sub TurnPage(ByRef Rs,PageSize) 'Rs 记录集 PageSize 每页显示的记录条数;
Dim TotalPage '总页数
Dim PageNo '当前显示的是第几页
Dim RecordCount '总记录条数
Rs.PageSize = PageSize
RecordCount = Rs.RecordCount
TotalPage = INT(RecordCount / PageSize * -1)*-1
PageNo = Request.QueryString ("PageNo")
wjxh=request.querystring("wjxh")
'直接输入页数跳转;
If Request.Form("PageNo")<>"" Then PageNo = Request.Form("PageNo")
'如果没有选择第几页,则默认显示第一页;
If PageNo = "" then PageNo = 1
If RecordCount <> 0 then
Rs.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 "<font face=webdings >9</font> <font face=webdings >7</font> <font face=webdings >8</font> <font face=webdings >:</font> "
Else%>
<a href="<%=fileName%>?PageNo=1&wjxh=<%=wjxh%>"><font face=webdings >9</font> </a>
<%If PageNo - 1 = 0 Then
Response.Write "<font face=webdings >7</font> "
Else%>
<a href="<%=fileName%>?PageNo=<%=PageNo-1%>&wjxh=<%=wjxh%>"><font face=webdings >7</font> </a>
<%End If

If PageNo+1 > TotalPage Then
Response.Write "<font face=webdings >8</font> "
Else%>
<a href="<%=fileName%>?PageNo=<%=PageNo+1%>&wjxh=<%=wjxh%>"><font face=webdings >8</font> </a>
<%End If%>

<a href="<%=fileName%>?PageNo=<%=TotalPage%>&wjxh=<%=wjxh%>"><font face=webdings >:</font> </a>
<%End If%></td>


</tr>
</table>
<%End Sub%>
<% sub break_code() '禁止复制代码
str="oncontextmenu='return false' ondragstart='return false' onselectstart='return false'"
response.write str
end sub
%>



在所需页面调用这个函数就可以翻页了,方法如下:
<%
sql="你的语句"
set rs=server.createobject("adodb.recordset")
RS.PageSize =20 '你设置一页显示的行
RowCount=RS.PageSize
rs.open sql,conn,1,1
%>
<%Call TurnPage(RS,RowCount)%> '参数是:所创的记录实例和显示行数

简单吧??
vivisogood 2003-10-20
  • 打赏
  • 举报
回复
打开页面用

http://website/页面.asp?txt_page=1
你也可以在前面就负好值
vivisogood 2003-10-20
  • 打赏
  • 举报
回复
这是 include.asp文件 用到分页的部分

首先链接数据库

<%
'-------------------------------- 取某表中纪录总数 -------------------------------------
Function Get_Count(Tablename)
Dim Rs_count,strQuery

strQuery = "select count(*) from " & Tablename
'Response.Write strQuery & "<br>"
Set Rs_count=Conn.Execute(strQuery)
Get_Count=Rs_count(0)
Rs_count.Close()
End Function

'------------------------- 输出当前页面的数据记录页数 ----------------------
Function Output_Pages(iCount,iCur,strURL)
Dim iTemp,i,j

iTemp=Int(iCur/10)
If iCount>10 and iTemp=(iCur/10) Then iTemp=iTemp-1

If iCount>0 Then
If iCount>10 and iCur>10 Then Response.Write ("<a href=" & strURL & (iTemp-1)*10+1 & ">" & "<<" & "</a>  ")

For i=1 to 10
If iCur<>iTemp*10+i Then
Response.Write("<a href=" & strURL & iTemp*10+i & ">" & iTemp*10+i & "</a> ")
Else
Response.Write iCur & " "
End If
If iTemp*10+i=iCount Then Exit For
Next

If iCount>10 and iCount>(iTemp+1)*10 Then Response.Write (" " & "<a href=" & strURL & (iTemp+1)*10+1 & ">" & ">></a>")
Else
Response.Write "0"
End If
End Function

'------------------------- 定义当前页iCurPage值(附属于下一函数) ----------------------
Function Define_iCurPage(strPage,iCount)
If strPage="" Then
strPage=1
Else
strPage=CInt(strPage)
End IF

If strPage<=1 then strPage=1
If strPage>=icount then strPage=iCount
Define_iCurPage=strPage
End Function

'------------------------- 定义记录集的相关属性(翻页用) ----------------------
Function Define_RecordSet_Property(Rs_sql,iNum,iPage)
If Rs_sql.recordcount<>0 then
Rs_sql.PageSize=iNum

iPageCount=Rs_sql.pagecount
iCurpage=Define_iCurPage(iPage,iPageCount)
Rs_sql.Absolutepage=iCurpage
Else
iCurPage=0
iPageCount=0
End If
End Function
%>
vivisogood 2003-10-20
  • 打赏
  • 举报
回复
里面的表。字段自己修改

<%@ Language = VBScript %>
<!--#include file = "../includes/include.asp"-->
<%
'on error resume next
'**************** 禁止页面缓存 ******************
Response.Expires = 0
Response.Expiresabsolute = Now() - 1
'Response.AddHeader "pragma","no-cache"
'Response.AddHeader "cache-control","private"
'Response.CacheControl = "no-cache"
'************************************************

dim Rs,strQuery,strWhere,i,Rs_temp,iCount,strInterest,str


if request("cb_delete") <> "" then
strQuery = "delete from Room_Info where Room_Info_ID in (" & request("cb_delete") & ")"
Conn.execute(strQuery)

end if


if Trim(request("section"))<>"" then
strWhere = strWhere & " id_section = " & Trim(request("section")) & " and "
str=str & "section=" & Request("section") & "&"
end if
strWhere = strWhere & " 1 = 1 "
'response.write strWhere
'response.end
%>
<html>
<HEAD>
<title></title>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link REL="stylesheet" HREF="style.css" TYPE="text/css">
<script language="JavaScript" src="../includes/include.js"></script>

</HEAD>
<BODY>

<form action="<%= Request.ServerVariables("SCRIPT_NAME") %>" method="post" name="f_search" onsubmit="javascript:return check(this);">

<%
strQuery = "select Count(*) from Room_Info where " & strWhere
set Rs = Conn.execute(strQuery)
iCount = Rs(0)
set Rs = nothing
%>
<br>

<table border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#F7F7F7">
<tr align="LEFT" bgcolor="#ffffff">

<td >
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="../images/classified_box_left.gif" height="21" alt="" border="0"></td>
<td bgcolor="B0C923">
<table border="0" cellspacing="0" cellpadding="0">
<tr>

<td align="left" valign="middle"class=title> 点击“添加客房种类”信息按钮添加信息</font></td>
<td align="right" valign="middle"></td>
</tr>
</table>
</td>
<td><img src="../images/classified_box_right.gif" height="21" alt="" border="0"></td>
</tr>
</table>
</td>
</tr>
</table>
<table border="1" cellspacing="0" cellpadding="0" align="center" bordercolor="#D0D5B5">
<tr>
<td>
<table border="0" cellspacing="2" cellpadding="2" align="center">
<tr>

<td align="right">
<input type="button" value="添加客房种类" style="cursor:hand;" class="content" onclick="javascript:fun_open_popup('Room_add.asp?section=<%= Request("section") %>',700,560);">
</td></tr>
<tr>
<td align="center">





<table border=0 cellPadding=2 cellSpacing=0 align=center>
<tr class=content valign = "top">
<%
if iCount > 0 then
dim iPageCount,iCurPage,iRow,iRec
iRec = 1
iRow = 5
strQuery = "select * from Room_Info where " & strWhere & " order by Room_Info_ID desc"
set Rs = server.CreateObject("ADODB.RECORDSET")
Rs.Open strQuery,Conn,3,1,1
Rs.CacheSize=iRow
Call Define_RecordSet_Property(Rs,iRow,request("txt_page"))


dim pageCount
if ((iCount/iRow)<>Int(iCount/iRow)) then
pagecount=Int(iCount/iRow+1)
else
pagecount=Int(iCount/iRow)
end if
%>
<td valign = "top" >
<table border="1" cellspacing="0" cellpadding="3" bordercolor="White">
<tr class=subtitle>
<td >客房种类</td>

<td>删除</td>
</tr>

<%
do while iRec<=iRow
if Rs.eof then exit do
%><tr class=content class=content <% if iRec mod 2 <> 0 then Response.Write "bgcolor=#E7E7D6" else Response.Write "bgcolor=#F3F4EC" end if%>>
<% irecnew=(request("txt_page")-1)*iRow
irecnew=irecnew+irec
%>
<td><%=irecnew%></td>
<td><%=Rs("Room_Type")%></td>


<td >
<INPUT type="checkbox" name="cb_delete" value="<% = Rs("Room_Info_ID")%>">
</td>
<%
iRec = iRec + 1
Rs.MoveNext
loop
%>
<tr class=title>
<td >
<input type="button" value="添加客房种类" style="cursor:hand;" class="content" onclick="javascript:fun_open_popup('Room_add.asp?section=<%= Request("section") %>',690,560);">
</td>
<td colspan="7" align="right">
<input type="submit" value="删除" class="content" style="cursor:hand;" onclick='javascript:return confirm("你真的要删除吗?");'>   </td>
</tr>
<tr >
<td colspan="8" align="right"><%=Output_Pages(pagecount,Int(trim(request("txt_page"))),"Room.asp?txt_Page=")%></td>
</tr>
</table>
<input type="hidden" value="<%=request("section")%>" name="section">
<input type="hidden" value="<%=request("txt_page")%>" name="txt_page">
</td>
</tr>

<%else%>

<td class=content><font color=red size=5><b>没有</b></font>
客房!</td>
</tr>
<% end if %>
</table>



</td>
</tr>

</table>
</td>
</tr>
</table>

</form>

</BODY>
</HTML>
不老书生 2003-10-20
  • 打赏
  • 举报
回复
<%
'================= ProgrammName: 分页函数 =======================
Function cutPage(sqlStr,Conn,dateNums,pageNums,URLs)'利用ADO分页的函数
Dim sql,Cn,dateNum,pageNum,URL,rsDate
Sql=Trim(sqlStr) '获得sql语句。
Set Cn=Conn '获得数据对象
dateNum=Cint(dateNums) '获得每页得记录数
pageNum=Cint(pageNums) '获得当前页码
URL=Trim(URLs) '获得路径
Set rsDate=Server.CreateObject("ADODB.Recordset")
rsDate.PageSize=dateNum
rsDate.Open Sql,cn,1,1
IF rsDate.Eof Then
Response.Write("<center><font stlye='font-size:14px;' color='#ff0000'>对不起,没有记录!</font></center>")
Else
IF pageNum="" or pageNum<1 Then
pageNum=1
ElseIf pageNum>rsDate.PageCount Then
pageNum=rsDate.PageCount
End IF
rsDate.absolutepage =pageNum
Dim recordHead,recordLast '定义当前页开头记录和结束记录
recordHead=1
If pageNum>1 Then recordHead=dateNum*(pageNum-1)
If pageNum>=rsDate.PageCount Then
recordLast=rsDate.RecordCount
Else
recordLast=dateNum*pageNum
End If
Response.Write("<table width=100% border='0' cellpadding='0' cellspacing='0' style='font-size:12px;'>")
Response.Write("<tr><td height=38 align=left><font stly='font-size:12px;'>(第"&recordHead&"-"&recordLast&"条,共"&rsDate.Recordcount&"条,每页显示"&dateNum&"条)</font></td></tr>")
Dim URLa '定义判断输入得URL包含?没有的变量
Dim upPage,downPage,allPage '定义向上和向下翻的变量
Dim allWrite '定义输出
upPage=pageNum-1
downPage=pageNum+1
URLa=Split(URL,"?",-1,1)
If URLa(0)=URL Then
upPage="<a href=" & URL & "?page=" & upPage &" stlye='font-size:12px;'>上一页</a> "
If pageNum=1 Then upPage=""
downPage="<a href=" & URL & "?page=" & downPage &" stlye='font-size:12px;'>下一页</a>"
If pageNum=rsDate.PageCount Then downPage=""
Else
upPage="<a href=" & URL & "&page=" & upPage &" stlye='font-size:12px;'>上一页</a> "
If pageNum=1 Then upPage=""
downPage="<a href=" & URL & "&page=" & downPage &" stlye='font-size:12px;'>下一页</a>"
If pageNum=rsDate.PageCount Then downPage=""
End If
allWrite=upPage & downPage & "  共" & rsDate.PageCount & "页 " & "目前第"& pageNum &"页"
allwrite="<font style='font-size:12px;'>" & allWrite & " 到第<input type='text' style='width:30px;'>页<input type='submit' value='GO'></font>"
Response.Write("<tr><form name='formPage' method='post' action="&URL&"><td height=30 align=right style='font-szie=12px;'>" & allWrite & "</td></form></tr>")
Response.Write("<tr><td align=center>")
Response.Write("<table width=100% border='0' cellpadding='0' cellspacing='0'>")
Response.Write("<tr>")
Response.Write("<tr bgcolor='#efffce' height=25>")
Dim id,i
For i=0 to rsDate.Fields.Count-1 '设置表头
Response.Write("<td align='center'><font style='font-size:14px;'><b>"&rsDate.Fields(i).Name&"</b></font></td>")
Next
Response.Write("</tr>")
id=0
While not rsDate.EOF and id<dateNum
id=id+1
If id Mod 2=0 then
Response.Write("<tr bgcolor=#f7f6e7>")
Else
Response.Write("<tr bgcolor=#ffffff>")
End If
For Each fils in rsDate.Fields
Response.Write("<td align='center' height=20>"&fils&"</td>")
Next
Response.Write("</tr>")
rsDate.MoveNext
Wend
Response.Write("<tr height=30 bgcolor='#efffce'>")
For i=0 to rsDate.Fields.Count-1 '设置表尾
Response.Write("<td align='center'><font style='font-size:14px;'><b>"&rsDate.Fields(i).Name&"</b></font></td>")
Next
Response.Write("</tr>")
Response.Write("</table></td></tr>")
Response.Write("<tr><form name='formPage1' method='post' action="&URL&"><td height=30 align=right>" & allWrite & "</td></form></tr>")
End IF
rsDate.close
Set rsDate=nothing
End Function

%>

page=request("page")
sql="select * from [table]"
url="xx.asp"Call cutPage(sql,conn,"3",page,url)'3代表每页显示3条记录

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧