手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Asp编程>列表

ASP控制表格的行列来显示数据

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!
很多时候,我们在显示数据库的内容时,会用到几行或几列来显示数据,如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 ("&nbsp;")
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">
<蔿l tablebody(kk,1,"")%>
</table>
<hr>

<table border="1" width="600" cellpadding="2">
<蔿l tablebody(kk,4,"test1")%>
</table>
<hr>

<table border="1" width="600" cellpadding="2">
<蔿l tablebody(kk,5,"")%>
</table>
<hr>
<%
dim wwwstr,wwwarr
wwwstr = "51windows.Net|blueidea.com|google.com|yahoo.com|msn.com.cn|csdn.net|ipark.cn|1kg.cn"
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">
<蔿l tablebody(wwwarr,3,"urltest1")%>
</table>
<hr>

<table border="2" width="480" cellpadding="2" cellspacing="2" >
<蔿l tablebody(wwwarr,4,"urltest2")%>
</table>

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!