日期:2014-05-17  浏览次数:20777 次

一组数据将其表现出来为6列的表格?
如果数据不足6列,用空列补足如: <td> &nbsp; </td>
用下列方式:
for   .....

if   ...
next  

thanks

------解决方案--------------------
if DataNum mod 6=0 then 'datanum是数据总数
rows=DataNum/6
else
rows=cint(DataNum/6)+1
end if
'得到行数
response.write " <table> "
for i=1 to rows
response.write " <tr> "
for j=1 to 6
if rs.eof then
response.write " <td> &nbsp; </td> "
else
response.write " <td> rs(字段) </td> "
rs.movenext
end if
next
response.write " </tr> "
if rs.eof then exit for
next
response.write " </table> "
------解决方案--------------------
不需要知道行数也可以实现
--------------------------
set rs=conn.execute(sql)
while not rs.eof
Response.Write " <tr> "
for i=1 to 6
if rs.eof then
showEmpty(6-i)
exit for
else
Response.Write " <td> &nbsp; " & rs(1) & " </td> "
end if
rs.movenext
next
Response.Write " </tr> "
wend

sub showEmpty(rows)
for i=0 to rows
Response.Write " <td> &nbsp; </td> "
next
end sub

Response.Write " <table> "
------解决方案--------------------
还有一种方式,可以使用rs.movenext,然后判断
比如
<tr>
<td> 第一条记录 </td>
<%
rs.movenext
if rs.eof then exit for
%>
<td> 第二条记录 </td>
<%
rs.movenext
if rs.eof then exit for
%>
<td> 第三条记录 </td>
</tr>

------解决方案--------------------
i=0
response.write " <table> <tr> "
while not rs.eof
i=i+1
Response.Write " <td> &nbsp; " & rs(1) & " </td> "
rs.movenext
if i mod 6=0 then Response.Write " </tr> <tr> "
wend
for j=1 to i mod 6
Response.Write " <td> &nbsp; </td> "
next
Response.Write " </tr> </table> "

这样貌似也可以。