asp下制做行背景颜色交替变换的表格
2018-09-06 12:09
<%
ConstadInteger=3
ConstadVarChar=200
声明变量
DimmyRecordset
DimiLetter
DimField
DimstrAltColor
DimbColor
bColor=False
此例利用内存中的recordset,你需要做的只是修改你的数据显示的部分就可以了。
SetmyRecordset=Server.CreateObject(ADODB.Recordset)
myRecordset.Fields.AppendID,adInteger
myRecordset.Fields.AppendTitle,adVarChar,25
myRecordset.Fields.AppendDescription,adVarChar,255
myRecordset.Open
FillRSwithsampledata:
ForiLetter=Asc(A)ToAsc(M)
myRecordset.AddNew
myRecordset.Fields(ID).Value=iLetter-64
myRecordset.Fields(Title).Value=字母:&Chr(iLetter)
myRecordset.Fields(Description).Value=这里测试字母:&Chr(iLetter)&.
myRecordset.Update
NextiLetter
移动到头部开始位置,以便下面的循环开始.
myRecordset.MoveFirst
在表格中显示数据
Response.Write<tableborder=0cellspacing=0cellpadding=3>&vbCrLf
表头
Response.WritevbTab&<tr>&vbCrLf
ForEachFieldinmyRecordset.Fields
Response.WritevbTab&vbTab&<tdbgcolor=#CCCCCC><strong>
Response.Write</strong></td>&vbCrLf
NextField
Response.WritevbTab&</tr>&vbCrLf
DoWhileNotmyRecordset.EOF
循环改变单元格的背景颜色
bColor=NotbColor
IfbColorThen
strAltColor=#FFFFFF
Else
strAltColor=#FF8040
EndIf
循环改变单元格的背景颜色
Response.WritevbTab&<tr>&vbCrLf
ForEachFieldinmyRecordset.Fields
Response.WritevbTab&vbTab&<tdbgcolor=
Response.WritestrAltColor
Response.Write>&Field.Value&</td>&vbCrLf
NextField
Response.WritevbTab&</tr>&vbCrLf
myRecordset.MoveNext
Loop
Endthetable
Response.Write</table>&vbCrLf
关闭对象、释放资源
myRecordset.Close
SetmyRecordset=Nothing
%>