ASP里如何实现既能换行又能分页呢??
<TABLEcellSpacing=0cellPadding=0border=0width="500"><%setrs2=server.CreateObject("ado...
<TABLE cellSpacing=0 cellPadding=0 border=0 width="500">
<%
set rs2=server.CreateObject("adodb.Recordset")
sql="Select * from photo order by id desc"
rs2.PageSize = 20 '这里设定每页显示的记录数
rs2.CursorLocation = 3
rs2.open sql,conn,1,3
pre = true
last = true
page = trim(Request.QueryString("page"))
if len(page) = 0 then
intpage = 1
pre = false
else
if cint(page) =< 1 then
intpage = 1
pre = false
else
if cint(page) >= rs2.PageCount then
intpage = rs2.PageCount
last = false
else
intpage = cint(page)
end if
end if
end if
if not rs2.eof then
rs2.AbsolutePage = intpage
end if
for i=1 to rs2.PageSize
if rs2.EOF or rs2.BOF then exit for
%>
<tr>
<%
j=0
do while not rs.eof
j=j+1
%>
<td align="center">
<br>
<img src="<%=rs2("url")%>" style="border: 3px solid #F2F2F2" onload="if(this.width>80)this.style.width=80;"></td>
<% if (j mod 5=0) and j>=2 then %> '取5条数据后换行
</tr>
<tr>
<%
end if
rs2.movenext
loop
%>
</tr>
</table>
<br>
<table width="350" border="0" cellpadding="0" cellspacing="0">
<tr>
<%if rs2.pagecount > 0 then%>
<td width="13%" align="left">当前页<%=intpage%>/<%=rs2.PageCount%></td>
<%else%>
<td width="41%" align="left">当前页0/0</td><%end if%>
<td width="46%" align="right"> <a href="photo.asp?page=1">首页</a> |
<%if pre then%>
<a href="photo.asp?page=<%=intpage -1%>">上页</a>| <%end if%>
<%if last then%>
<a href="photo.asp?page=<%=intpage +1%>">下页</a> |<%end if%>
<a href="photo.asp?page=<%=rs.PageCount%>">尾页</a> | 转到第
<select name="sel_page" onchange="javascript:location=this.options[this.selectedIndex].value;">
<%
for i = 1 to rs2.PageCount
if i = intpage then%>
<option value="photo.asp?page=<%=i%>" selected><%=i%></option>
<%else%>
<option value="photo.asp?page=<%=i%>"><%=i%></option>
<%
end if
next
%>
</select>页</font>
</td>
</tr>
</table>
<%
rs2.close
set rs2=nothing
%>
我运行以上代码时出错
提示:循环语句中(for)无效
是因为分页代码中不使用do while not rs.eof 和 loop的
而换行代码中必须有do while not rs.eof 和 loop,现在想把这两个功能用到一起
怎样实现啊?? 展开
<%
set rs2=server.CreateObject("adodb.Recordset")
sql="Select * from photo order by id desc"
rs2.PageSize = 20 '这里设定每页显示的记录数
rs2.CursorLocation = 3
rs2.open sql,conn,1,3
pre = true
last = true
page = trim(Request.QueryString("page"))
if len(page) = 0 then
intpage = 1
pre = false
else
if cint(page) =< 1 then
intpage = 1
pre = false
else
if cint(page) >= rs2.PageCount then
intpage = rs2.PageCount
last = false
else
intpage = cint(page)
end if
end if
end if
if not rs2.eof then
rs2.AbsolutePage = intpage
end if
for i=1 to rs2.PageSize
if rs2.EOF or rs2.BOF then exit for
%>
<tr>
<%
j=0
do while not rs.eof
j=j+1
%>
<td align="center">
<br>
<img src="<%=rs2("url")%>" style="border: 3px solid #F2F2F2" onload="if(this.width>80)this.style.width=80;"></td>
<% if (j mod 5=0) and j>=2 then %> '取5条数据后换行
</tr>
<tr>
<%
end if
rs2.movenext
loop
%>
</tr>
</table>
<br>
<table width="350" border="0" cellpadding="0" cellspacing="0">
<tr>
<%if rs2.pagecount > 0 then%>
<td width="13%" align="left">当前页<%=intpage%>/<%=rs2.PageCount%></td>
<%else%>
<td width="41%" align="left">当前页0/0</td><%end if%>
<td width="46%" align="right"> <a href="photo.asp?page=1">首页</a> |
<%if pre then%>
<a href="photo.asp?page=<%=intpage -1%>">上页</a>| <%end if%>
<%if last then%>
<a href="photo.asp?page=<%=intpage +1%>">下页</a> |<%end if%>
<a href="photo.asp?page=<%=rs.PageCount%>">尾页</a> | 转到第
<select name="sel_page" onchange="javascript:location=this.options[this.selectedIndex].value;">
<%
for i = 1 to rs2.PageCount
if i = intpage then%>
<option value="photo.asp?page=<%=i%>" selected><%=i%></option>
<%else%>
<option value="photo.asp?page=<%=i%>"><%=i%></option>
<%
end if
next
%>
</select>页</font>
</td>
</tr>
</table>
<%
rs2.close
set rs2=nothing
%>
我运行以上代码时出错
提示:循环语句中(for)无效
是因为分页代码中不使用do while not rs.eof 和 loop的
而换行代码中必须有do while not rs.eof 和 loop,现在想把这两个功能用到一起
怎样实现啊?? 展开
展开全部
给一段代码你 自己好好看一下 初略的测试了 是可以的 自己拓展一下 就行了
<%
set rs=server.CreateObject("adodb.recordset")
if pid="" then
sql="select * from Products_2L order by orderby desc"
else
sql="select * from Products_2L where big_id="&cint(pid)&" order by orderby desc"
end if
rs.open sql,conn,1,1
if not rs.eof then
rs.PageSize =8 '每页记录条数
iCount=rs.RecordCount '记录总数
iPageSize=rs.PageSize
maxpage=rs.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
rs.AbsolutePage=Page
if page=maxpage then
x=iCount-(maxpage-1)*iPageSize
else
x=iPageSize
end if
end if
for i=1 to 2
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-top:10px">
<tr>
<%
for j=1 to 4
if rs.eof then exit for
%>
<td align="left" style="line-height:35px ">
<table width="166" border="0" cellspacing="3" cellpadding="0">
<tr>
<td width="154" class="k2"><a href="<%=rs("pic")%>" rel="lightbox[roadtrip]"><img src="<%=rs("pic")%>" width="150" height="110" border="0" /></a></td>
</tr>
<tr>
<td align="center"><a href="<%=rs("pic")%>" rel="lightbox[roadtrip]"><%=rs("pdt_name")%></a></td>
</tr>
<tr>
<td align="center"><a href="message.asp?pdt_name=<%=server.URLEncode(rs("pdt_name"))%>" class="a1">点击订购</a></td>
</tr>
</table>
</td>
<%
rs.MoveNext()
next
%>
</tr>
</table>
<%
next
rs.Close()
set rs = nothing
%>
<table cellpadding="0" cellspacing="0" width="100%">
<tr><td height="25" align="center"><%call PageControl(iCount,maxpage,page)%></td></tr>
</table>
<%
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 style=font-size:12px;>" & vbCrLf )
Response.Write("<form method=get onsubmit=""document.location = '" & action & "?" & temp & "Page='+ this.page.value;return false;""><TR>" & vbCrLf )
Response.Write("<TD align=right>" & vbCrLf )
Response.Write(font_style & vbCrLf )
if page<=1 then
Response.Write ("首页 " & vbCrLf)
Response.Write ("上页 " & vbCrLf)
else
Response.Write("<A HREF=" & action & "?" & temp & "Page=1>首页</A> " & vbCrLf)
Response.Write("<A HREF=" & action & "?" & temp & "Page=" & (Page-1) & ">上页</A> " & vbCrLf)
end if
if page>=pagecount then
Response.Write ("下页 " & vbCrLf)
Response.Write ("尾页 " & vbCrLf)
else
Response.Write("<A HREF=" & action & "?" & temp & "Page=" & (Page+1) & ">下页</A> " & vbCrLf)
Response.Write("<A HREF=" & action & "?" & temp & "Page=" & pagecount & ">尾页</A> " & vbCrLf)
end if
Response.Write(" 页次:" & page & "/" & pageCount & "页" & vbCrLf)
Response.Write(" 共有" & iCount & "条记录" & vbCrLf)
Response.Write(" 转到" & "<INPUT TYEP=TEXT NAME=page SIZE=1 Maxlength=5 VALUE=" & page & ">" & "页" & vbCrLf & "<INPUT type=submit style=""font-size: 9pt"" value=GO class=b2>")
Response.Write("</TD>" & vbCrLf )
Response.Write("</TR></form>" & vbCrLf )
Response.Write("</table>" & vbCrLf )
End Sub
%>
<%
set rs=server.CreateObject("adodb.recordset")
if pid="" then
sql="select * from Products_2L order by orderby desc"
else
sql="select * from Products_2L where big_id="&cint(pid)&" order by orderby desc"
end if
rs.open sql,conn,1,1
if not rs.eof then
rs.PageSize =8 '每页记录条数
iCount=rs.RecordCount '记录总数
iPageSize=rs.PageSize
maxpage=rs.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
rs.AbsolutePage=Page
if page=maxpage then
x=iCount-(maxpage-1)*iPageSize
else
x=iPageSize
end if
end if
for i=1 to 2
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-top:10px">
<tr>
<%
for j=1 to 4
if rs.eof then exit for
%>
<td align="left" style="line-height:35px ">
<table width="166" border="0" cellspacing="3" cellpadding="0">
<tr>
<td width="154" class="k2"><a href="<%=rs("pic")%>" rel="lightbox[roadtrip]"><img src="<%=rs("pic")%>" width="150" height="110" border="0" /></a></td>
</tr>
<tr>
<td align="center"><a href="<%=rs("pic")%>" rel="lightbox[roadtrip]"><%=rs("pdt_name")%></a></td>
</tr>
<tr>
<td align="center"><a href="message.asp?pdt_name=<%=server.URLEncode(rs("pdt_name"))%>" class="a1">点击订购</a></td>
</tr>
</table>
</td>
<%
rs.MoveNext()
next
%>
</tr>
</table>
<%
next
rs.Close()
set rs = nothing
%>
<table cellpadding="0" cellspacing="0" width="100%">
<tr><td height="25" align="center"><%call PageControl(iCount,maxpage,page)%></td></tr>
</table>
<%
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 style=font-size:12px;>" & vbCrLf )
Response.Write("<form method=get onsubmit=""document.location = '" & action & "?" & temp & "Page='+ this.page.value;return false;""><TR>" & vbCrLf )
Response.Write("<TD align=right>" & vbCrLf )
Response.Write(font_style & vbCrLf )
if page<=1 then
Response.Write ("首页 " & vbCrLf)
Response.Write ("上页 " & vbCrLf)
else
Response.Write("<A HREF=" & action & "?" & temp & "Page=1>首页</A> " & vbCrLf)
Response.Write("<A HREF=" & action & "?" & temp & "Page=" & (Page-1) & ">上页</A> " & vbCrLf)
end if
if page>=pagecount then
Response.Write ("下页 " & vbCrLf)
Response.Write ("尾页 " & vbCrLf)
else
Response.Write("<A HREF=" & action & "?" & temp & "Page=" & (Page+1) & ">下页</A> " & vbCrLf)
Response.Write("<A HREF=" & action & "?" & temp & "Page=" & pagecount & ">尾页</A> " & vbCrLf)
end if
Response.Write(" 页次:" & page & "/" & pageCount & "页" & vbCrLf)
Response.Write(" 共有" & iCount & "条记录" & vbCrLf)
Response.Write(" 转到" & "<INPUT TYEP=TEXT NAME=page SIZE=1 Maxlength=5 VALUE=" & page & ">" & "页" & vbCrLf & "<INPUT type=submit style=""font-size: 9pt"" value=GO class=b2>")
Response.Write("</TD>" & vbCrLf )
Response.Write("</TR></form>" & vbCrLf )
Response.Write("</table>" & vbCrLf )
End Sub
%>
展开全部
<%
i=0
for j=1 to PagesCount
if j=ipage then
Response.Write "<font color=" &PageNumColor_Curr& ">[" &cstr(j)&"]</font> "
else
Response.Write "<a href=index.asp?page=" & cstr(j) & "><font color=" &PageNumColor_Normal& ">[" &cstr(j)&"]</font></a> "
end If
i=i+1
If i Mod 25 = 0 Then response.write "<br />"
next
%>
i=0
for j=1 to PagesCount
if j=ipage then
Response.Write "<font color=" &PageNumColor_Curr& ">[" &cstr(j)&"]</font> "
else
Response.Write "<a href=index.asp?page=" & cstr(j) & "><font color=" &PageNumColor_Normal& ">[" &cstr(j)&"]</font></a> "
end If
i=i+1
If i Mod 25 = 0 Then response.write "<br />"
next
%>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询