| ASP实现动态生成网页中表格的行和列 |
|
| |
|
|
有时候,需要在某个表格列内放一定数量的文字和图片,并需要随着记录数动态的显示一定的行数和列数,比如在一行内显示4张图片抑或是5张图片,用Table实现的时候有时候很难判断tr或者td的结束位置,这里我写了一段代码,能实时判断行列的结束位置,记录集中的数据不足时能自动添加空tr和td。
测试用表格
'Create Table Test(id int,sTitle varchar(50))
程序代码
'测试每行排4列,排四行 dim i,j dim iRsCount,iRows dim perLines perLines=4 '每行需显示的列数 set objRs=server.CreateObject("adodb.recordset") objRs.open "select top 16 * from Test order by id",conn,3,1 if not objRs.eof then response.write "<table width=""100%"" cellpadding=""0"" cellspacing=""8"">"&vbcrlf iRsCount=objRs.recordcount '取得实际的记录数 iRows=int(iRsCount/perLines) '计算可得到的行数 if iRows<1 then iRows=1 else if iRsCount mod perLines=0 then iRows=int(iRsCount/perLines) else iRows=int(iRsCount/perLines)+1 end if end if i=1 while not objRs.eof for i=1 to iRows response.write "<tr>"&vbcrlf for j=1 to perLines If Not objRs.eof then response.write "<td width=""25%""><div align=""center"">"&objRs("sTitle")&"</div></td>"&vbcrlf Else response.write "<td> </td>"&vbcrlf End if if not objRs.eof then objRs.movenext next response.write "</tr>"&vbcrlf next Wend response.write "</table>" end if objRs.close set objRs=nothing
 |
频道声明:本频道的文章除部分特别声明禁止转载的专稿外,可以自由转载.但请务必注明出出处和原始作者 文章版权归本频道与文章作者所有.对于被频道转载文章的个人和网站,我们表示深深的谢意。
| 原始作者:佚名 |
录入时间:2007-6-3 12:02:06 |
| 信息来源:不详 |
投稿信箱:itqoo@126.com |
|
|
 |
|
|
|
| 教程录入:itqoo 责任编辑:itqoo |
|
上一个教程: ASP初学参考:常见错误代号解释
下一个教程: 实例讲解ASP动态网页制作中使用SQL语句 |
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |