1、 将 ASP 纪录集输出成 n 列的的表格形式显示的方法前些日子有网友问:将 ASP 纪录集输出成 n 列的的表格形式显示的方法,现在写了一个,方便大家使用。定义变量Dim cn,rs,SqlSql = “select CustomerID from Orders“记录总数Dim TotalNumbeSet cn = Server.CreateObject(“ADODB.Connection“)cn.Open “Provider=SQLOLEDB.1;User ID=sa;Initial Catalog=NorthWind;Data Source=.;Password=;“Set rs = S
2、erver.CreateObject(“ADODB.Recordset“)rs.Open Sql, cn, 3, 1TotalNumber = rs.RecordCountIf TotalNumber = 0 ThenResponse.Write “没有记录输出。“ElseDim jj,nLeft,cColjj = 0nCol = 415nLeft = nCol- (TotalNumber Mod nCol)If nLeft = nCol Then nLeft = 0Response.Write “table bordertr“ vbCrLfWhile not rs.EOFResponse.W
3、rite “td“ rs(“CustomerID“) “/td“ vbCrLfIf (jj Mod nCol) = (nCol - 1) And jj TotalNumber - 1 Then Response.Write “/trtr“ vbCrLfIf (jj Mod nCol) = (nCol - 1) And jj = TotalNumber-1 Then Response.Write “/tr“ vbCrLfIf (jj Mod nCol) = (nCol - 1) ThenIf jj TotalNumber - 1 ThenResponse.Write “/trtr“ vbCrLf
4、ElseResponse.Write “/tr“ vbCrLfEnd IfEnd Ifjj = jj + 1rs.MoveNextWendIf nLeft 0 And nLeft nCol ThenIf nCol TotalNumber ThenFor i = 1 to nLeftResponse.Write “td /td“ vbCrLfNextEnd IfResponse.Write “/tr“ vbCrLfEnd IfResponse.Write “/table“End Ifrs.CloseSet rs = Nothingcn.CloseSet cn = NothingResponse.End