Asp教程

通过asp实例结合结合ACCESS,MSSQL来更好的深入Asp学习 - 爬坡者

« 判断域名进行跳转的js代码1句话日期函数的13种写法 »

[原]多行多列产品展示+分页

'------------------
'作者:Man
'来自:www.papozhe.com
'2007-9-3
'DESCRIPTON
网上现在的产品展示实现几行几列的很多,但很多没有分页,今天群里一个大哥要做,我就花了点时间,做的比较粗糙
要的自己回家改去
注:用css+div就简单多了。本人忙先不改了,至于这篇文章的标题,也不知道叫什么好,暂时先这样,待完善
'-------------------

未分页版本

<!--#include file="Conn.asp"-->

<table cellpadding="0" cellspacing="5"><tr>
<%
dim rs,i,StrSql
set rs=server.createobject("adodb.recordset")
StrSql="select top 25 * from [Product]"
   rs.open StrSql,conn,1,1

if rs.eof or rs.bof then
  response.Write "没有记录"
end if

i=1
while not (rs.Eof or rs.Bof)
if i mod 5 =0 then
%>

<td Style="height:80px;width:120px;border:solid 1px #00f;padding:3px;">
第<%=i%>个产品<br />
产品名称:<%=rs("productName")%><br />
产品价格:<%=rs("Price")%><br />
产品描述:<%=rs("DesCription")%><br />
产品点击:<%=rs("hit")%><br />
</td>
</tr><tr>
<%else%>
<td Style="height:80px;width:120px;border:solid 1px #00f;padding:3px;">
第<%=i%>个产品<br />
产品名称:<%=rs("productName")%><br />
产品价格:<%=rs("Price")%><br />
产品描述:<%=rs("DesCription")%><br />
产品点击:<%=rs("hit")%><br />
</td>
<%end if%>
<%
rs.MoveNext
i=i+1
Wend
rs.Close
set rs=nothing
%>
</tr></table>

分页版本

<!--#include file="Conn.asp"-->
<!--#include file="ClsSplitPages.asp"-->
<%dim sp,num,Rs,ProductNum
num=15'每页记录条数
set sp=new SplitPages'建立分页类对像
sp.conn=conn'传弟一个记录集
sp.ListFields="*"'筛选的数据列
sp.TableName="product"'表名
sp.OrderString="order by productID asc"'排序方式
sp.Unit="条记录"'记录单位
sp.sizePages=num
sp.ListNum=10'列出当前页附近的几页
'-----------------------
If Request.querystring("pages")="" Then
ProductNum=0
else
ProductNum = num*Cint(Request.querystring("pages")-1)
end If
'-----------------------
%>

分页版本
<table cellpadding="0" cellspacing="5"><tr>
<%Dim i
set rs=sp.GetRS()'取得记录集
if rs.eof then
response.write "<div>暂时还没有记录</div>"
response.End()
End If
for i=1 to num
%>
<%
if i mod 5 =0 then
%>

<td Style="height:80px;width:120px;border:solid 1px #00f;padding:3px;">
第<%=ProductNum+i%>个产品<br />
产品名称:<font color=red><%=rs("productName")%></font><br />
产品价格:<%=rs("Price")%><br />
产品描述:<%=rs("DesCription")%><br />
产品点击:<%=rs("hit")%><br />
</td>
</tr><tr>
<%else%>
<td Style="height:80px;width:120px;border:solid 1px #00f;padding:3px;">
第<%=ProductNum+i%>个产品<br />
产品名称:<%=rs("productName")%><br />
产品价格:<%=rs("Price")%><br />
产品描述:<%=rs("DesCription")%><br />
产品点击:<%=rs("hit")%><br />
</td>
<%end if%>
  <%
  Rs.movenext
  next%>
  </tr>
</table>
<div align="center"><%sp.ShowPage()%></div>
<%
if err.number<>0 then
response.write "error!"
end if
rs.Close
set rs = nothing
%>

全部代码含数据库,点这里下载

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Spirit Build 80710

Copyright 2007-2008 papozhe.com [asp教程] All Rights Reserved.
浙ICP备07030537号
免责申明:所有文章除特别声明,均来自网上,主要为学习用!内容仅供参考,版权归原作者。如侵犯您利益,请来信告知.
Email:papozhe$Gmail.com QQ:76336503