| ASP实用技巧:控制表格的行列来显示数据 |
|
| |
|
很多时候,我们在显示数据库的内容时,会用到几行或几列来显示数据,如10条数据,要以每行2列或3列形式显示。
下面是一个使用数组以表格显示几行几列的简单的示列代码,希望对您有所帮助。
<% function tablebody(arr,cols,functionstr) 'arr为数组 'cols为列数 'functionstr为输出内容用的function,没有为空
dim allnum,i,j allnum = ubound(arr) for i = 0 to (allnum/cols) Response.write (VbTab &"<tr>" & VbNewLine) for j = 0 to (cols-1) ij = (i*cols+j) Response.write (VbTab & VbTab &"<td width="""& formatnumber(100/cols,0) &"%"">") if ij <= allnum then if len(functionstr) > 0 then execute(""& functionstr &"(arr(ij))") else Response.write (arr(ij)) end if else Response.write (" ") end if Response.write ("</td>" & VbNewLine) next Response.write (VbTab &"</tr>" & VbNewLine) next end function
function test1(str) Response.write ("<div align=""center"">"& str &"</div>") end function
'示例1 dim kk(9) for k = 0 to 9 kk(k) = k+1 next %> <table border="1" width="600" cellpadding="2"> <%call tablebody(kk,1,"")%> </table> <hr>
<table border="1" width="600" cellpadding="2"> <%call tablebody(kk,4,"test1")%> </table> <hr>
<table border="1" width="600" cellpadding="2"> <%call tablebody(kk,5,"")%> </table> <hr> <% dim wwwstr,wwwarr wwwstr = "webjx.com|163.com|google.com|yahoo.com|baidu.com|sina.com|sina.cn|qq.com" wwwarr = split(wwwstr,"|")
function urltest1(str) Response.write ("<a href=""http://www."& str &""" target=""_blank"">"& str &"</a>") end function
function urltest2(str) Response.write ("<button style=""width:100%;"" onclick=""window.open('http://www."& str &"','','')"">"& str &"</button>") end function %> <table border="1" width="480" cellpadding="2"> <%call tablebody(wwwarr,3,"urltest1")%> </table> <hr>
<table border="2" width="480" cellpadding="2" cellspacing="2" > <%call tablebody(wwwarr,4,"urltest2")%> </table>
 |
频道声明:本频道的文章除部分特别声明禁止转载的专稿外,可以自由转载.但请务必注明出出处和原始作者 文章版权归本频道与文章作者所有.对于被频道转载文章的个人和网站,我们表示深深的谢意。
| 原始作者:佚名 |
录入时间:2007-6-20 17:06:32 |
| 信息来源:不详 |
投稿信箱:itqoo@126.com |
|
|
 |
|
|
|
| 教程录入:itqoo 责任编辑:itqoo |
|
上一个教程: ASP技巧:在Access数据库中重命名表
下一个教程: ASP实例:Asp 防止网页频繁刷新一法 |
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |