.NEt专家博客!

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

上一篇 / 下一篇  2008-07-22 14:24:39 / 个人分类:.net

将ASP纪录集输出成n列的的表格形式显示的方法:
Z9S3XGH0
RKxs\6R0'定义变量
:Z"w? s7G H&C0Dim cn,rs,Sql

Sql = "select CustomerID from Orders"

 '记录总数
hH.Bk7Rh&]:G0Dim TotalNumbeITPUB个人空间/E%q*Jj{9W
Set cn = Server.CreateObject("ADODB.Connection")ITPUB个人空间B\;L9MJ/h7E*{
cn.Open "Provider=SQLOLEDB.1;User ID=sa;Initial Catalog=NorthWind;Data Source=.;Password=;"

Set rs = Server.CreateObject("ADODB.Recordset")ITPUB个人空间RO3N_,}!Y7[.J
rs.Open Sql, cn, 3, 1
rf tt^;w(}a%X0TotalNumber = rs.RecordCount
p wI"\)V!D0If TotalNumber = 0 Then
3R%oJ kI_#N1xrb0 Response.Write "没有记录输出。"
k$j;d Q4cd0ElseITPUB个人空间1?i"L/| B q
 Dim jj,nLeft,cColITPUB个人空间0A$?%qtj1G0m
 jj = 0ITPUB个人空间l~1_)a%i f\u)Esrk
 nCol = 415
:s,Qc6o)P`P"Cl#u0 nLeft = nCol- (TotalNumber Mod nCol)
*TbHM Q0R5nP F0 If nLeft = nCol Then nLeft = 0
'dG O,g/D0 Response.Write "<table border><tr>" & vbCrLfITPUB个人空间W;a(lNn-p'l
 While not rs.EOF
.\F,{/zY]0  Response.Write "<td>" &  rs("CustomerID") & "</td>" & vbCrLf
bX^:J^*j/Z-y m k0  'If (jj Mod nCol) = (nCol - 1) And jj <> TotalNumber - 1 Then Response.Write "</tr><tr>" & vbCrLf
c [(Gpf],a N0  'If (jj Mod nCol) = (nCol - 1) And jj = TotalNumber-1  Then Response.Write "</tr>" & vbCrLf
-}%zK4FiB0  
2d}R\zH I0  If (jj Mod nCol) = (nCol - 1) Then
-|0Y#sTwc;}g0   If jj <> TotalNumber - 1 Then
S1F t1F @G@(f*U0    Response.Write "</tr><tr>" & vbCrLf
2vK:VM*mai(w4D0   Else
(C0V3PvU@bkUG$r _%h0    Response.Write "</tr>" & vbCrLf
%Bm2Tx7E0o2{0   End IfITPUB个人空间%c4q.o HPgc
  End IfITPUB个人空间 }I"W#i8RhM/Fvb}
  jj = jj + 1
T H*j7BJBB0  rs.MoveNextITPUB个人空间 Z.i^ DR
 WendITPUB个人空间 \+Tp4v F5zGG5]
 If nLeft <> 0 And nLeft <> nCol Then
B PbF/TeaP p0  If nCol < TotalNumber Then
y(IL[2S0   For i = 1 to nLeft
JM7[%X(p2NCD%~6|r0    Response.Write "<td>&nbsp;</td>" & vbCrLf
;P@ L7a#^&yp+|"u0   NextITPUB个人空间#L b_f6TC7q
  End IfITPUB个人空间1CIH&ZfT.i7b G
  Response.Write "</tr>" & vbCrLf
0h}mC1|0 End If
%p$fOWm_l$w0 Response.Write "</table>"
j0FE/O9Y0End IfITPUB个人空间;],y%at%zs T_
rs.CloseITPUB个人空间 x2C4~ np
Set rs = NothingITPUB个人空间!fkGQj;V5y;z
cn.Close
}WPjLb)K0Set cn = NothingITPUB个人空间~ HB2~]}v Z
Response.End


TAG: 微软

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-10-12  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 46833
  • 日志数: 1203
  • 影音数: 7
  • 文件数: 1
  • 建立时间: 2008-01-04
  • 更新时间: 2008-10-10

RSS订阅

Open Toolbar