asp.net listview Alternate background Color Implementation Code _ Practical skills

Source: Internet
Author: User
One line of code:
Copy Code code as follows:

<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:
Copy Code code as follows:

<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> Select all and change tr color </title>
<script language= "JavaScript" type= "Text/javascript" for= "checkbox" event= "onclick" ><!--
Tr_bgcolor (this);
--></script>
<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]);
}
}
--></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;" style= "Background-color: #eee;" &GT;&LT;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" 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" 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" 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" style= "Background-color: #eee" ><td><input type= "checkbox" Name= " CheckBox "/></td><td>***********************</td></tr>
</table>
</td></tr>
</table>
</form>
</body>

Or
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> table row TR color alternating </title>
<style><!--
#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><style 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>
<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";
}
}
--></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>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.