将ASP纪录集输出成n列的的表格形式显示的方法

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 net_lover 的 blog

前些日子有网友问:将asp纪录集输出成n列的的表格形式显示的方法,现在写了一个,方便大家使用。
'定义变量
dim cn,rs,sql

sql = "select customerid from orders"

 '记录总数
dim totalnumbe
set cn = server.createobject("adodb.connection")
cn.open "provider=sqloledb.1;user id=sa;initial catalog=northwind;data source=.;password=;"

set rs = server.createobject("adodb.recordset")
rs.open sql, cn, 3, 1
totalnumber = rs.recordcount
if totalnumber = 0 then
 response.write "没有记录输出。"
else
 dim jj,nleft,ccol
 jj = 0
 ncol = 415
 nleft = ncol- (totalnumber mod ncol)
 if nleft = ncol then nleft = 0
 response.write "<table border><tr>" & vbcrlf
 while not rs.eof
  response.write "<td>" &  rs("customerid") & "</td>" & vbcrlf
  'if (jj mod ncol) = (ncol - 1) and jj <> totalnumber - 1 then response.write "</tr><tr>" & vbcrlf
  'if (jj mod ncol) = (ncol - 1) and jj = totalnumber-1  then response.write "</tr>" & vbcrlf
  
  if (jj mod ncol) = (ncol - 1) then
   if jj <> totalnumber - 1 then
    response.write "</tr><tr>" & vbcrlf
   else
    response.write "</tr>" & vbcrlf
   end if
  end if
  jj = jj + 1
  rs.movenext
 wend
 if nleft <> 0 and nleft <> ncol then
  if ncol < totalnumber then
   for i = 1 to nleft
    response.write "<td>&nbsp;</td>" & vbcrlf
   next
  end if
  response.write "</tr>" & vbcrlf
 end if
 response.write "</table>"
end if
rs.close
set rs = nothing
cn.close
set cn = nothing
response.end

 

本文关键:将ASP纪录集输出成n列的的表格形式显示的方法
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top