ASP中如何实现先横向再纵向的排列

来源:互联网 发布:淘宝删除子账号后 编辑:程序博客网 时间:2024/05/21 14:49
比如一共提取的15条记录,现在需要形成 5行3列 的显示样式,这就是“先横向再纵向排列”最实际的问题。

分析,横的可直接采用表格的<td>,当然起先需要<tr>行标签的给出

if (i mod 3=1) then
document.write"<tr>"
end if


需要在一行显示几个记录,就使用几个<td>这个循环简单

只有当换到下一行的时候,即需要</tr>结束转换的时候,这就需要判断了。

if (i mod 3=0) then
document.write"</tr>"
end if

看一个例子

<table border=1>
<script language=vbs>
for i=1 to 28
if (i mod 3=1) then
document.write"<tr>"
end if

document.write"<td><img src=/forum/icon/icon"&i&".gif><br>/bbs/icon/icon"&i&".gif</td>"

if (i mod 3=0) then
document.write"</tr>"
end if

next
</script>
</table>

再来个嵌套表格的

<table>
<script language=vbs>
for i=1 to 15
if (i mod 3=1) then
document.write"<tr>"
end if
document.write"<td><table border=0 width=100><tr><td><img src=/forum/icon/icon"&i&".gif></td></tr>"
document.write"<tr><td>icon"&i&".gif</td></tr></table></td>"
if (i mod 3=0) then
document.write"</tr>"
end if

next
</script>
</table>

当然上面的这个在<td>单元格中有嵌套了一个表格,此嵌套表格包含同等的相关数据库记录行。

至于ASP中也同样的道理

<%
strsql = "select * from Your_table"
objrs.open strsql,conn,1,1
%>
<table width=""100%"" align='center'>
<%
for i=1 to objrs.recordCount '变量i从1循环到数据库中的全部记录数
if (i mod 3 =1) then '每个tr显示3个记录,可根据需要自行修改
response.write "<tr>"
end if
response.write "<td>"&objrs("title")&"</td>"
if (i mod 5 = 0) then
response.write "</tr>"
end if
objrs.movenext
next
objrs.close
%>
</table>

如果要使用复杂多条信息。则在

response.write "<td>"&objrs("title")&"</td>"

期间继续添加 嵌套表格即可。