asp.net ListView交替背景颜色实现代码

所属分类: 网络编程 / ASP.NET 阅读数: 1207
收藏 0 赞 0 分享
只一行代码:
复制代码 代码如下:

<tr style="<%# (Container.DisplayIndex%2==0)?"background-color:white;":"background-color:#EEEEEE;" %>">

另外还有直接用js处理整个页面中所有tr的交替色:
复制代码 代码如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>全选并改变TR颜色</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>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#888888">
<tr><td><input name="selectall" type="checkbox" value="全选" 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;"><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>
</html>


复制代码 代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>表格行tr颜色交替</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>
</head>
<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>
</html>
更多精彩内容其他人还在看

解析WPF实现音频文件循环顺序播放的解决方法

本篇文章是对WPF实现音频文件循环顺序播放的方法进行了详细的分析介绍,需要的朋友参考下
收藏 0 赞 0 分享

解决.net framework 4.0环境下遇到版本不同编译不通过的方法详解

本篇文章是对.net framework 4.0环境下遇到版本不同编译不通过的解决方法进行了详细的分析介绍,需要的朋友参考下
收藏 0 赞 0 分享

将文件上传、下载(以二进制流保存到数据库)实现代码

将文件以二进制流的格式写入数据库:首先获得文件路径,然后将文件以二进制读出保存在一个二进制数组中具体请祥看本文,希望对你有所帮助
收藏 0 赞 0 分享

点击提交按钮后DropDownList的值变为默认值实现分析

在点击提交按钮后,页面上所有的绑定到数据库的控件值都恢复到默认值,下面与大家分享下DropDownList的值变为默认值
收藏 0 赞 0 分享

ASP.NET web.config中数据库连接字符串connectionStrings节的配置方法

ASP.NET web.config中数据库连接字符串connectionStrings节的配置方法,需要的朋友可以参考一下
收藏 0 赞 0 分享

Linkbutton控件在项目中的简单应用

Button控件可分为button控件、LinkButton控件、ImageButton控件三类,而LinkButton控件则在页面上显示为一个超级链接,下面与大家分享下其具体应用
收藏 0 赞 0 分享

Web.config 和 App.config 的区别分析

Web.config 和 App.config 的区别分析,需要的朋友可以参考一下
收藏 0 赞 0 分享

基于.Net中的数字与日期格式化规则助记词的使用详解

本篇文章是对.Net中的数字与日期格式化规则助记词的使用进行了详细的分析介绍,需要的朋友参考下
收藏 0 赞 0 分享

解决在Web.config或App.config中添加自定义配置的方法详解

本篇文章是对在Web.config或App.config中添加自定义配置的方法进行了详细的分析介绍,需要的朋友参考下
收藏 0 赞 0 分享

深入本机影像生成器(Ngen.exe)工具使用方法详解

本篇文章是对本机影像生成器(Ngen.exe)工具使用方法进行了详细的分析介绍,需要的朋友参考下
收藏 0 赞 0 分享
查看更多