首先分別定義奇數行和偶數行的式樣(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