asp中,一个字段里数据如何分页?

asp中,一个字段里数据如何分页?,第1张

给你一段分页代码 好好看
<!--#include file=conn1asp-->
<%
dim m,n
set rs=serverCreateObject("adodbrecordset")
sqlstr="select from message order by time desc"
rsopen sqlstr,conn,3,3
rspagesize=10 '定义一页显示的记录数目
tatalrecord=rsrecordcount '获取记录总数目
tatalpages=rspagecount '获取分页的数目
rsmovefirst
----------------------------
nowpage=request("page") '用request获取当前页数,注意page是自己定义的变量并非函数
--------------------------
if nowpage&"x"="x" then '处理页码为空时的情况
nowpage=1
else
nowpage=cint(nowpage) '将页码转换成数字型
end if
--------------------------------
rsabsolutepage=nowpage '将指针移动到当前显示页的第一条记录
-------------------------------
%>
---------------------------------------------
<%
n=1
while not rseof and n<=rspagesize
responseWrite(rs("user") & "<br>")
responseWrite(rs("tt") & "<br>")
n=n+1
rsmovenext '显示页面的数据
wend
%>
-------------------------------------------
共:<%=tatalpages%>页 当前为:<%=nowpage%>页
<%if nowpage>1 then%>
<a href="fyasppage=<%=nowpage-1%>">上一页</a>
<%else%>
上一页
<%end if%>
<%for k=1 to tatalpages%>
<%if k<>nowpage then %>
<a href="fyasppage=<%=k%>"><%=k%></a>
<%else%>
<%=k%>
<%end if%>
<%next%>
<%if nowpage < tatalpages then%>
<a href="fyasppage=<%=nowpage+1%>">下一页</a>
<%else%>
下一页
<%end if%> '加上页码连接
<%if nowpage<>1 then%>
<a href="fyasppage=<%=1%>"> 首页</a>
<%else%>
首页
<%end if%>
<%if nowpage<>tatalpages then %>
<a href="fyasppage=<%=tatalpages%>">末页</a>
<%else%>
末页
<%end if%>

我可以上传一段正在运营当中的网站的分页代码,这个是网址,你可以看下,我上传的是进入这个网站“七彩真石”栏目下的分页代码。
其实思路不是很麻烦:最外层是一个一行一列的大的table,在<td></td>中利用div的 float:left 样式来控制 让 div 横向排列 具体横向排列几个可以控制div的宽度来调节,我这里是横向排列4列。具体代码如下:
<!--#include file="Inc/TemplateConnection1asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 10 Transitional//EN" "">
<html xmlns="">
<head>
<style type="text/css">
company_right
company_word
good_img
good_div1
</style>
</head>
<body>
<div class="company_right">
<div class="company_word">
<table border="0" cellpadding="0" style="width:100%;">
<tr>
<td style="width:100%;">
<%
Set rs=ServerCreateObject("ADODBRecordSet")
sql="select from 表名"
rsopen sql,conn,1,1
if rsbof and rseof then
responseWrite("<div style='width:100%;line-height:380px;text-align:center;color:#FF0000;'>暂无产品信息</div>")
else
rsPageSize = 24
rsCursorLocation = 3
rsOpen sql,conn,0,2,1
pre = true
last = true
page = trim(RequestQueryString("page"))
if len(page) = 0 then
intpage = 1
pre = false
else
if cint(page) =< 1 then
intpage = 1
pre = false
else
if cint(page) >= rsPageCount then
intpage = rsPageCount
last = false
else
intpage = cint(page)
end if
end if
end if
if not rseof then
rsAbsolutePage = intpage
end if
for i=1 to rsPageSize
if rsEOF or rsBOF then exit for
%>
<div class="good_div1">
<div class="good_img">
<a href="url"><img src="<%= rs("ProductImageSrc")%>" width="124" height="83" /></a>
</div>
<div class="good_title">
<table border="0" cellpadding="0" cellspacing="0" width="128"><tr><td>标题</td></tr>
</table>
</div>
</div>
<%
rsmovenext
next
%>
</td>
</tr>
<tr><td>
<div style="text-align:right; margin-right:15px;">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="100%" align="right" style="height:35px; line-height:35px;">
<%if rspagecount > 0 then%>
当前页<font color="#FF0000"><%=intpage%></font>/<%=rsPageCount%>
<%else%>
当前页0/0<%end if%>  <font color="#FF0000"><%= rsPageSize %></font>条记录/页
<a href="qczsasppage=1">首页</a>  
<%if pre then%>
<a href="qczsasppage=<%=intpage -1%>">上页</a>  <%end if%>
<%if last then%>
<a href="qczsasppage=<%=intpage +1%>">下页</a>  <%end if%>
<a href="qczsasppage=<%=rsPageCount%>">尾页</a>  转到第
<select name="sel_page" onchange="javascript:location=thisoptions[thisselectedIndex]value;">
<%
for i = 1 to rsPageCount
if i = intpage then%>
<option value="qczsasppage=<%=i%>" selected><%=i%></option>
<%else%>
<option value="qczsasppage=<%=i%>"><%=i%></option>
<%
end if
next
%>
</select>页
</td>
</tr>
</table>
</div>
<%
end if
rsclose
set rs=nothing
%>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>
你做适当的修改就可以了,希望我的回答能给你一些帮助

rsPageSize=10
Page=CLng(request("Page"))
if Page<1 then Page=1
if Page>rsPageCount then Page=rsPageCount
rsmovefirst
rsabsolutepage=Page
放在
rsopen sql,conn,1,1
do while not rseof
两行中间
<p>
<%
if page<>1 then
responseWrite "<a href=xxxasppage=1>第一页</a>"
responseWrite "<a href=xxxasppage=" & (page-1) & ">上一页</a>"
end if
if page<>rspagecount then
responseWrite "<a href=xxxasppage=" & (page+1) & ">下一页</a>"
responseWrite "<a href=xxxasppage=" & rspagecount & ">最后一页</a>"
end if
%>
</p>
<p>第<%=page%>页 共<%=rspagecount%>页</p>
这一段看放哪合适放哪

<%
Const maxPagesize=1000 '设置分页字数
Function InsertPageBreak(strText)
Dim strPagebreak,s,ss
Dim i,IsCount,c,iCount,strTemp,Temp_String,Temp_Array
strPagebreak="[hiweb_break]"
s=strText
If Len(s)<maxPagesize Then
InsertPageBreak=s
End If
s=Replace(s, strPagebreak, "")
s=Replace(s, " ", "< >")
s=Replace(s, ">", "<>>")
s=Replace(s, "<", "<<>")
s=Replace(s, """, "<">")
s=Replace(s, "'", "<'>")
If s<>"" and maxPagesize<>0 and InStr(1,s,strPagebreak)=0 then
IsCount=True
Temp_String=""
For i= 1 To Len(s)
c=Mid(s,i,1)
If c="<" Then
IsCount=False
ElseIf c=">" Then
IsCount=True
Else
If IsCount=True Then
If Abs(Asc(c))>255 Then
iCount=iCount+2
Else
iCount=iCount+1
End If
If iCount>=maxPagesize And i<Len(s) Then
strTemp=Left(s,i)
If CheckPagination(strTemp,"table|a|b>|i>|strong|div|span") then
Temp_String=Temp_String & Trim(CStr(i)) & ","
iCount=0
End If
End If
End If
End If
Next
If Len(Temp_String)>1 Then Temp_String=Left(Temp_String,Len(Temp_String)-1)
Temp_Array=Split(Temp_String,",")
For i = UBound(Temp_Array) To LBound(Temp_Array) Step -1
ss = Mid(s,Temp_Array(i)+1)
If Len(ss) > 380 Then
s=Left(s,Temp_Array(i)) & strPagebreak & ss
Else
s=Left(s,Temp_Array(i)) & ss
End If
Next
End If
s=Replace(s, "< >", " ")
s=Replace(s, "<>>", ">")
s=Replace(s, "<<>", "<")
s=Replace(s, "<">", """)
s=Replace(s, "<'>", "'")
InsertPageBreak=s
End Function
Function CheckPagination(strTemp,strFind)
Dim i,n,m_ingBeginNum,m_intEndNum
Dim m_strBegin,m_strEnd,FindArray
strTemp=LCase(strTemp)
strFind=LCase(strFind)
If strTemp<>"" and strFind<>"" then
FindArray=split(strFind,"|")
For i = 0 to Ubound(FindArray)
m_strBegin="<"&FindArray(i)
m_strEnd ="</"&FindArray(i)
n=0
do while instr(n+1,strTemp,m_strBegin)<>0
n=instr(n+1,strTemp,m_strBegin)
m_ingBeginNum=m_ingBeginNum+1
Loop
n=0
do while instr(n+1,strTemp,m_strEnd)<>0
n=instr(n+1,strTemp,m_strEnd)
m_intEndNum=m_intEndNum+1
Loop
If m_intEndNum=m_ingBeginNum then
CheckPagination=True
Else
CheckPagination=False
Exit Function
End If
Next
Else
CheckPagination=False
End If
End Function
Function ContentPagination(hiwebstr)
Dim ContentLen, maxperpage, Paginate
Dim arrContent, strContent, i
Dim m_strFileUrl,m_strFileExt,ArticleID
ArticleID=RequestQueryString("ID")
strContent = InsertPageBreak(hiwebstr)
ContentLen = Len(strContent)
CurrentPage=RequestQueryString("Page")
If CurrentPage="" Then CurrentPage=0
If InStr(strContent, "[hiweb_break]") <= 0 Then
ArticleContent = "<div id=""NewsContentLabel"" class=""NewsContent"">" & strContent & "</div><div id=""Message"" class=""Message""></div>"
Else
arrContent = Split(strContent, "[hiweb_break]")
Paginate = UBound(arrContent) + 1
If CurrentPage = 0 Then
CurrentPage = 1
Else
CurrentPage = CLng(CurrentPage)
End If
If CurrentPage < 1 Then CurrentPage = 1
If CurrentPage > Paginate Then CurrentPage = Paginate
strContent = "<div id=""NewsContentLabel"" class=""NewsContent"">"& arrContent(CurrentPage - 1)
ArticleContent = ArticleContent & strContent
If UserArticle = True Then
ArticleContent = ArticleContent & "</p></div><div id=""Message"" class=""Message""></div><p align=""center""><b>"
Else
ArticleContent = ArticleContent & "</p></div><p align=""center""><b>"
End If
If IsURLRewrite Then
m_strFileUrl = ArticleID & "_"
Else
m_strFileExt = ""
m_strFileUrl = "id=" & ArticleID & "&Page="
End If
If CurrentPage > 1 Then
If IsURLRewrite And (CurrentPage-1) = 1 Then
ArticleContent = ArticleContent & "<a href="""& ArticleID & m_strFileExt & """>上一页</a>  "
Else
ArticleContent = ArticleContent & "<a href="""& m_strFileUrl & CurrentPage - 1 & m_strFileExt & """>上一页</a>  "
End If
End If
For i = 1 To Paginate
If i = CurrentPage Then
ArticleContent = ArticleContent & "<font color=""red"">[" & CStr(i) & "]</font> "
Else
If IsURLRewrite And i = 1 Then
ArticleContent = ArticleContent & "<a href="""& ArticleID & m_strFileExt & """>[" & i & "]</a> "
Else
ArticleContent = ArticleContent & "<a href="""& m_strFileUrl & i & m_strFileExt & """>[" & i & "]</a> "
End if
End If
Next
If CurrentPage < Paginate Then
ArticleContent = ArticleContent & " <a href="""& m_strFileUrl & CurrentPage + 1 & m_strFileExt & """>下一页</a>"
End If
ArticleContent = ArticleContent & "</b></p>"
End If
ResponseWrite(ArticleContent)
End Function
%>
这段代码我没有用过,你不妨自己研究研究,前辈给我的,文章内容过长自动分页代码asp

不会ASP
给你点提示
int size =10;// 每页显示数目
int pageNum =10;//
for i in 1:pageNum
select top 10 id not in(select top (i-1)pageNum id from Photo order by SomeAttr ) from Photo order by SomeAttr
希望对你有所帮助!

我来试试看:
<!--#include file="connasp"-->
<%
set rsc=servercreateobject("adodbrecordset")
sqlc="select from news where class='"&rs("class")&"' order by id desc"
rscopen sqlc,conn,1,1
Responsewrite "<center>"
rscPageSize = 10 'pagesize属性指定了每页要显示的记录条数
Page = CLng(Request("Page")) ’string型转化为long型
If Page < 1 Then Page = 1
If Page > rscPageCount Then Page = rscPageCount
If Page <> 1 Then
ResponseWrite "<A HREF=emp1aspPage=1>第一页</A>�"
ResponseWrite "<A HREF=emp1aspPage=" & (Page-1) & ">上一页</A>�"
End If
If Page <> rscPageCount Then
ResponseWrite "<A HREF=emp1aspPage=" & (Page+1) & ">下一页</A>�"
ResponseWrite "<A HREF=emp1aspPage="& rscPageCount & ">最后一页</A>�"
End If
Responsewrite "页码:" & Page & "/" & rscPageCount & "</center><table border=1>"
rscAbsolutePage = Page '把页码赋给absolutepage属性从而知当前页的首条记录号
For iPage = 1 To rscPageSize
%>
<tr>
<td width="574" bordercolor="#CCCCCC" class="classlist"><div align="left" class="classlist"><span class="classlist"><a href="newsaspid=<%=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>
<%
rscMoveNext
If rscEOF 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>
<%
rsclose
rscclose
set rs=nothing
set rsc=nothing
connclose
set conn=nothing
%>

百度下,网上有很多这个方面的源码下
down了一段下来。。呵呵
我跟个通用分页 :) 大家修改一点都可以用 简单修改可以用了。
<%
'SQL语句自己设置
sql="select from table where id=8 order by id desc"
Set rs= ServerCreateObject("ADODBRecordset")
rsopen sql,conn,1,1
if rseof and rsbof then
responsewrite "<p align='center'> 还 没 有 任 何 文 章 </p>"
else
totalPut=rsrecordcount
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
showpage totalput,MaxPerPage,"manageasp"
showContent
showpage totalput,MaxPerPage,"manageasp"
else
if (currentPage-1)MaxPerPage<totalPut then
rsmove (currentPage-1)MaxPerPage
showpage totalput,MaxPerPage,"manageasp"
'文件名字简单修改
showContent
showpage totalput,MaxPerPage,"manageasp"
else
currentPage=1
showpage totalput,MaxPerPage,"manageasp"
showContent
showpage totalput,MaxPerPage,"manageasp"
end if
end if
rsclose
end if

set rs=nothing
connclose
set conn=nothing
%>
<%
'下面是显示内容部分
sub showContent
dim i
i=0
%>
<!--你的内容显示部分-->
<%
i=i+1
if i>=MaxPerPage then exit do
rsmovenext
loop
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
responsewrite "<p align='center'> "
if CurrentPage<2 then
responsewrite "<font color='#000080'>首页 上一页</font> "
else
responsewrite "<a href="&filename&"page=1&txtitle="&title&">首页</a> "
responsewrite "<a href="&filename&"page="&CurrentPage-1&"&txtitle="&title&">上一页</a> "
end if
if n-currentpage<1 then
responsewrite "<font color='#000080'>下一页 尾页</font>"
else
responsewrite "<a href="&filename&"page="&(CurrentPage+1)&"&txtitle="&title&">"
responsewrite "下一页</a> <a href="&filename&"page="&n&"&txtitle="&title&">尾页</a>"
end if
responsewrite "<font color='#000080'> 页次:</font><strong><font color=red>"&CurrentPage&"</font><font color='#000080'>/"&n&"</strong>页</font> "
responsewrite "<font color='#000080'> 共<b>"&totalnumber&"</b>个文档 <b>"&maxperpage&"</b>个文档/页</font> "

end function
%>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/13200096.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-06-19
下一篇 2023-06-19

发表评论

登录后才能评论

评论列表(0条)

保存