asp下制做行背景颜色交替变换的表格
程序员文章站
2022-07-12 08:17:52
<% const adinteger = 3 const advarchar = 200 '&...
<%
const adinteger = 3
const advarchar = 200
' 声明变量
dim myrecordset
dim iletter
dim field
dim straltcolor
dim bcolor
bcolor = false
' 此例利用内存中的recordset,你需要做的只是修改你的数据显示的部分就可以了。
set myrecordset = server.createobject("adodb.recordset")
myrecordset.fields.append "id", adinteger
myrecordset.fields.append "title", advarchar, 25
myrecordset.fields.append "description", advarchar, 255
myrecordset.open
' fill rs with sample data:
for iletter = asc("a") to asc("m")
myrecordset.addnew
myrecordset.fields("id").value = iletter - 64
myrecordset.fields("title").value = "字母:" & chr(iletter)
myrecordset.fields("description").value = "这里测试字母:" & chr(iletter) & "."
myrecordset.update
next 'iletter
'移动到头部开始位置,以便下面的循环开始.
myrecordset.movefirst
' 在表格中显示数据
response.write "<table border=""0"" cellspacing=""0"" cellpadding=""3"">" & vbcrlf
'表头
response.write vbtab & "<tr>" & vbcrlf
for each field in myrecordset.fields
response.write vbtab & vbtab & "<td bgcolor=""#cccccc""><strong>"
response.write field.name
response.write "</strong></td>" & vbcrlf
next 'field
response.write vbtab & "</tr>" & vbcrlf
do while not myrecordset.eof
' 循环改变单元格的背景颜色
bcolor = not bcolor
if bcolor then
straltcolor = "#ffffff"
else
straltcolor = "#ff8040"
end if
'循环改变单元格的背景颜色
response.write vbtab & "<tr>" & vbcrlf
for each field in myrecordset.fields
response.write vbtab & vbtab & "<td bgcolor="""
response.write straltcolor
response.write """>" & field.value & "</td>" & vbcrlf
next 'field
response.write vbtab & "</tr>" & vbcrlf
myrecordset.movenext
loop
' end the table
response.write "</table>" & vbcrlf
' 关闭对象、释放资源
myrecordset.close
set myrecordset = nothing
%>
const adinteger = 3
const advarchar = 200
' 声明变量
dim myrecordset
dim iletter
dim field
dim straltcolor
dim bcolor
bcolor = false
' 此例利用内存中的recordset,你需要做的只是修改你的数据显示的部分就可以了。
set myrecordset = server.createobject("adodb.recordset")
myrecordset.fields.append "id", adinteger
myrecordset.fields.append "title", advarchar, 25
myrecordset.fields.append "description", advarchar, 255
myrecordset.open
' fill rs with sample data:
for iletter = asc("a") to asc("m")
myrecordset.addnew
myrecordset.fields("id").value = iletter - 64
myrecordset.fields("title").value = "字母:" & chr(iletter)
myrecordset.fields("description").value = "这里测试字母:" & chr(iletter) & "."
myrecordset.update
next 'iletter
'移动到头部开始位置,以便下面的循环开始.
myrecordset.movefirst
' 在表格中显示数据
response.write "<table border=""0"" cellspacing=""0"" cellpadding=""3"">" & vbcrlf
'表头
response.write vbtab & "<tr>" & vbcrlf
for each field in myrecordset.fields
response.write vbtab & vbtab & "<td bgcolor=""#cccccc""><strong>"
response.write field.name
response.write "</strong></td>" & vbcrlf
next 'field
response.write vbtab & "</tr>" & vbcrlf
do while not myrecordset.eof
' 循环改变单元格的背景颜色
bcolor = not bcolor
if bcolor then
straltcolor = "#ffffff"
else
straltcolor = "#ff8040"
end if
'循环改变单元格的背景颜色
response.write vbtab & "<tr>" & vbcrlf
for each field in myrecordset.fields
response.write vbtab & vbtab & "<td bgcolor="""
response.write straltcolor
response.write """>" & field.value & "</td>" & vbcrlf
next 'field
response.write vbtab & "</tr>" & vbcrlf
myrecordset.movenext
loop
' end the table
response.write "</table>" & vbcrlf
' 关闭对象、释放资源
myrecordset.close
set myrecordset = nothing
%>
上一篇: 晚餐只吃苹果能减肥吗,怎么样才能减肥成功
推荐阅读