asp实现表格3列5行

2018-09-06 11:57

阅读:280

  方案一
复制代码 代码如下:<!--#includefile=conn.asp-->
<%
owen1=request(owen1)
owen2=request(owen2)
%>


<tablewidth=95%border=0cellpadding=0cellspacing=0>
<%
page=clng(request(page))
Setrs=Server.CreateObject(ADODB.RecordSet)
ifowen1<>andowen2<>then
sql=select*fromnewswhereBigClassName=&owen1&andSmallClassName=&owen2&orderbyiddesc
rs.Opensql,conn,1,1
elseifowen1<>then
sql=select*fromnewswhereBigClassName=&owen1&orderbyiddesc
rs.Opensql,conn,1,1
endif
ifrs.eofandrs.bofthen
response.Write(暂时没有记录)
else
%>

<%
rs.PageSize=15
ifpage=0thenpage=1
pages=rs.pagecount
ifpage>pagesthenpage=pages
rs.AbsolutePage=page
forj=1tors.PageSize
if(j-1)mod3=0thenResponse.Write(<tr>)
%>
<tdheight=24align=center>
<divalign=center><imgsrc=uppic/<%=RS(firstImageName)%>width=130height=100border=0/><ahref=onews.asp?id=<%=RS(id)%>><br>
<%=RS(TITLE)%></a></div></td>
<%
ifjmod3=0thenResponse.Write(</tr>)
rs.movenext
ifrs.eofthenexitfor
next
%>
<%
endif
rs.close
setrs=nothing
%>
</table>
方案二、
复制代码 代码如下:<!--#includefile=conn.asp-->
<%
owen1=request(owen1)
owen2=request(owen2)
%>


<tablewidth=95%border=0cellpadding=0cellspacing=0>
<%
page=clng(request(page))
Setrs=Server.CreateObject(ADODB.RecordSet)
ifowen1<>andowen2<>then
sql=select*fromnewswhereBigClassName=&owen1&andSmallClassName=&owen2&orderbyiddesc
rs.Opensql,conn,1,1
elseifowen1<>then
sql=select*fromnewswhereBigClassName=&owen1&orderbyiddesc
rs.Opensql,conn,1,1
endif
ifrs.eofandrs.bofthen
response.Write(暂时没有记录)
else
%>

<%
rs.PageSize=15
ifpage=0thenpage=1
pages=rs.pagecount
ifpage>pagesthenpage=pages
rs.AbsolutePage=page
forj=1to(rs.PageSize/3)
Response.Write(<tr>)
fori=1to3
%>
<tdheight=24align=center>
<divalign=center><imgsrc=uppic/<%=RS(firstImageName)%>width=130height=100border=0/><ahref=onews.asp?id=<%=RS(id)%>><br>
<%=RS(TITLE)%></a></div></td>
<%
rs.movenext
ifrs.eofthenexitfor
next
Response.Write(</tr>)
next
%>
<%
endif
rs.close
setrs=nothing
%>
</table>
上面的代码有缺点..

就是如果是16条那么页面最后一行会空出两列页面很难看因为如果16最后一行只显示一列这样少了两个<td></td>

必须进行判断总数/3的余数

if(rs.recordcountmod3=2)thenresponse.write(<td></td>)
if(rs.recordcountmod3=1)thenresponse.write(<td></td><td></td>)

这样页面才完整的


评论


亲,登录后才可以留言!