设为首页
加入收藏
站内地图
旧版入口
当前位置:首页 > 站长学院 > 网络编程 > ASP

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

作者:佚名 出处:网络转载 时间:01-07 点击:

内容载入中...

很多时候,我们在显示数据库的内容时,会用到几行或几列来显示数据,如10条数据,要以每行2列或3列形式显示。

  下面是一个使用数组以表格显示几行几列的简单的示列代码,希望对您有所帮助。

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

<table border="1" width="480" cellpadding="2">
<%call tablebody(wwwarr,3,"urltest1")%>
</table>

函数代码:

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

收藏本文:
】【打印页面】【推荐给朋友】【关闭窗口

站长学院

推荐信息