ASP 双色表格,

来源:互联网 发布:网红方媛的淘宝店链接 编辑:程序博客网 时间:2024/04/30 22:05

一、CSS样式
首先分别定义奇数行和偶数行的式样(CSS样式部份):


<style type="text/css">
.BgColorWhite {  
background-color: #FFFFFF; /*奇数行,我定义为白色背景*/
}
.BgColorGray {
      background-color: #EFEFEF; /*偶数行,我定义为灰色背景*/
      }
</style>


然后在程序中给定你的表格的单元格一个变量,如:<%=CSSName%>,把这个变量做为<tr>单元格的样式
程序代码:


<table width="90%" height="20" border="0" align="center" cellpadding="0" cellspacing="0" >
<%
Set rs=Server.CreateObject("ADODB.RecordSet")
if owen1<>"" and owen2 <>"" then
sql="select * from news where BigClassName='"&owen1&"' and SmallClassName='"&owen2&"' order by id desc"
rs.Open sql,conn,1,1
elseif owen1<>"" then
sql="select * from news where BigClassName='"&owen1&"' order by id desc"
rs.Open sql,conn,1,1
end if
if rs.eof and rs.bof then
    response.Write("暂时没有记录")
else
%>

<%
i=i+1  
    if i mod 2 = 0 then     '如果能被2整除(为偶数行)
        CSSName="BgColorGray"   
    else     '否则(为单数行)
        CSSName="BgColorWhite"   
    end if   
%>

<!--把单元格的样式设为变量-->
<tr class=<%=CSSName%>>
                            <td width="2%" height="20" align="center"><img src="Images/Ico/IcoArrow.gif" width="12" height="7" align="absmiddle" /></td>
                            <td width="63%" height="20" align="left"><% if rs("imagenum")<>"0" then response.write "<img src='images/news.gif' border=0 alt='图片新闻'>" end if %>
                              <a href="shownews.asp?id=<%= RS("id") %>" target="_blank"><%= RS("TITLE") %></a></td>
                            <td width="35%" align="right"><a href="shownews.asp?id=<%= RS("id") %>" target="_blank"></a> <span class="DateAndTime">[<%= RS("infotime") %>]</span> </td>
                          </tr>
                          <%
rs.movenext ‘移动到下一条记录
if rs.eof then exit for
next
%>    
</table>      
二、VB样式
<script language="vbscript">
document.write "<table bgcolor=#000000 cellspacing=1 border=0 style=font-size:9pt width=200>"
for i = 1 to 10
  if (i mod 2) then
      bcolor="#efefef"
  else
      bcolor="#ffffff"
  end if
document.write "<tr bgcolor="&bcolor&"><td>第"&i&"行</td></tr>"
next
document.write "</table>"
</script>

原创粉丝点击