One line of code:
<tr style= "<%# (container.displayindex%2==0)?" Background-color:white; ":" Background-color: #EEEEEE; "%>" >
There is also a direct use of JS processing the entire page of all TR alternating color:
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> website Special Effects Tutorial | linkweb.cn/js|---Select all and change tr color </title>
<mce:script language= "JavaScript" type= "Text/javascript Tutorial" for= "checkbox" event= "onclick" ><!--
Tr_bgcolor (this);
--></mce:script>
<mce:script language= "JavaScript" type= "Text/javascript" ><!--
function Tr_bgcolor (c) {
var tr = C.parentnode.parentnode;
Tr.rowindex% 2 = 0? Tr.style.backgroundColor = c.checked? ' #add6a6 ': ' #eee ': Tr.style.backgroundColor = c.checked? ' #add6d6 ': ';
}
function Selall (obj) {
for (var i=0; i<obj.form.elements.length; i++)
if (Obj.form.elements[i].type = = ' checkbox ' && obj.form.elements[i]!= obj) {
obj.form.elements[i].checked = obj.checked;
Tr_bgcolor (Obj.form.elements[i]);
}
}
--></mce:script>
<body>
<form id= "Form1" Name= "Form1" method= "Post" action= "" >
<table width= "border=" 0 "align=" center "cellpadding=" 0 "cellspacing=" 1 "bgcolor=" #888888 ">
<tr><td><input name= "SelectAll" type= "checkbox" value= "Select All" onclick= "Selall (This)"/></td> </tr>
<tr><td>
<table width= "100%" border= "0" cellpadding= "0" cellspacing= "0" bgcolor= "#FFFFFF" >
<tr style= "Background-color: #eee;" mce_style= "Background-color: #eee;" ><TD width= "6%" ><input type= "checkbox" name= "checkbox"/></td><td width= "94%" >********** </td></tr>
<tr><td><input type= "checkbox" name= "checkbox"/></td><td>*********************** </td></tr>
<tr style= "Background-color: #eee" mce_style= "Background-color: #eee" ><td><input type= "checkbox" Name = "checkbox"/></td><td>***********************</td></tr>
<tr><td><input type= "checkbox" name= "checkbox"/></td><td>*********************** </td></tr>
<tr style= "Background-color: #eee" mce_style= "Background-color: #eee" ><td><input type= "checkbox" Name = "checkbox"/></td><td>***********************</td></tr>
<tr><td><input type= "checkbox" name= "checkbox"/></td><td>*********************** </td></tr>
<tr style= "Background-color: #eee" mce_style= "Background-color: #eee" ><td><input type= "checkbox" Name = "checkbox"/></td><td>***********************</td></tr>
<tr><td><input type= "checkbox" name= "checkbox"/></td><td>*********************** </td></tr>
<tr style= "Background-color: #eee" mce_style= "Background-color: #eee" ><td><input type= "checkbox" Name = "checkbox"/></td><td>***********************</td></tr>
</table>
</td></tr>
</table>
</form>
</body>
Or
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
http://www.w3.org/1999/xhtml" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> table row TR color alternating </title>
<mce:style><!--
#ab {border-collaps tutorial e:collapse;width:800px;margin:10px Auto;}
#ab td{border:1px solid #ccc; border-top:none;padding:4px;text-align:center;}
. Tr1{background-color: #eee; color:red;}
. tr2 {background-color: #ccc; color:blue;}
--></mce:style><style mce_bogus= "1" > #ab {border-collapse:collapse;width:800px;margin:10px auto;}
#ab td{border:1px solid #ccc; border-top:none;padding:4px;text-align:center;}
. Tr1{background-color: #eee; color:red;}
. tr2 {background-color: #ccc; color:blue;} </style>
<mce:script type= "Text/javascript" ><!--
function COLORTD (ob) {
Obob=ob.rows;
for (Var i=0;i<ob.length;i++) {
if (i%2) OB (i) classname= "TR1";
else OB (i). Classname= "TR2";
}
}
--></mce:script>
<body onload= "COLORTD (AB)" >
<table id= "AB" >
<tr><td>hang------------1</td></tr>
<tr><td>hang------------2</td></tr>
<tr><td>hang------------3</td></tr>
<tr><td>hang------------4</td></tr>
</table>
</body>