GridView在查看数据时用户要求有鼠标移进移出和点击某行时有颜色变化

 1         protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
 2         {
 3             //增加背景行的颜色
 4             //判断是否是数据行
 5             if (e.Row.RowType == DataControlRowType.DataRow)
 6             {
 7 
 8 
 9                 //第一种方式
10                 //鼠标移动到某行上,该行变色,这部分为更改鼠标背景色的,一些系统默认的颜色
11                 //e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#6EA4DB'");
12                 //e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
13 
14                 //第二种方式用图片替换鼠标背景色的,需配合前台CSS代码如下:
15                 /*
16                   <style type="text/css">
17                      .selectRow
18                        {
19                            background-image:url(images/crm_1.gif);
20                        } 
21                   </style>
22                  */
23                 e.Row.Attributes.Add("onmouseover", "c=this.className;this.className='selectRow';");
24                 e.Row.Attributes.Add("onmouseout", "this.className=c");
25 
26 
27                 //当单击GridView的行,整行变色需配合前台Script代码如下:
28                 /*
29                   function selectx(row) {
30                     if (prevselitem != null) {
31                         prevselitem.style.backgroundColor = '#ffffff';
32                     }
33                     row.style.backgroundColor = 'PeachPuff';
34                     prevselitem = row;
35                 }
36                  */
37                 e.Row.Attributes.Add("onclick", e.Row.ClientID.ToString() + ".checked=true;selectx(this)");//点击行变色
38             }
39         }
View Code

 

posted on 2015-01-15 08:42  larry_fu  阅读(175)  评论(0)    收藏  举报

导航