GridView控件鼠标移动某行改变背景颜色

1   using  System;   
 
2   using  System.Data;   
 
3   using  System.Configuration;   
 
4   using  System.Collections;   
 
5   using  System.Web;   
 
6   using  System.Web.Security;   
 
7   using  System.Web.UI;   
 
8   using  System.Web.UI.WebControls;   
 
9   using  System.Web.UI.WebControls.WebParts;   
10   using  System.Web.UI.HtmlControls;   
11     
12   public   partial   class  Demo19 : System.Web.UI.Page   
13  {   
14       protected   void  Page_Load( object  sender, EventArgs e)   
15      {   
16           if  (Page.IsPostBack  ==   false )   
17          {   
18              BindData();   
19          }              
20      }   
21     
22       public   void  BindData()   
23      {   
24           string  strSql  =   " select UserID,C_Name,E_Name,UpdataDate,QQ from Demo_User  " ;   
25          DataTable dt  =  SqlHelper.ExecuteDataset(SqlHelper.CONN_STRING, CommandType.Text, strSql,  null ).Tables[ 0 ];   
26     
27          GridView.DataSource  =  dt;   
28          GridView.DataKeyNames  =   new   string [] {  " UserID "  }; // 主键   
29          GridView.DataBind();   
30      }   
31     
32       protected   void  GridView_PageIndexChanging( object  sender, GridViewPageEventArgs e)   
33      {   
34          GridView.PageIndex  =  e.NewPageIndex;   
35          BindData();   
36      }   
37     
38       protected   void  GridView_RowDataBound( object  sender, GridViewRowEventArgs e)   
39      {   
40           if  (e.Row.RowType  ==  DataControlRowType.DataRow)   
41          {   
42               // 鼠标经过时,行背景色变    
43              e.Row.Attributes.Add( " onmouseover " " this.style.backgroundColor='#00A9FF' " );   
44               // 鼠标移出时,行背景色变    
45              e.Row.Attributes.Add( " onmouseout " " this.style.backgroundColor='#FFFFFF' " );   
46          }   
47      }   
48  }    
  
 
1   < table align = " center "  bgcolor = " #c0de98 "  border = " 0 "  cellpadding = " 0 "  cellspacing = " 1 "  width = " 99% " >    
 
2           < tr >    
 
3               < th colspan = " 2 " >    
 
4                  GridView演示 th >    
 
5           tr >         
 
6          < tr >    
 
7              < td colspan = " 2 "  style = " width: 100%; "   >    
 
8                 < asp:GridView ID = " GridView "  runat = " server "  Width = " 100% "  AutoGenerateColumns = " False "  AllowPaging = " True "  OnPageIndexChanging = " GridView_PageIndexChanging "  PageSize = " 12 "  OnRowDataBound = " GridView_RowDataBound "   >    
 
9                   < Columns >    
10                         < asp:BoundField DataField = " UserID "  HeaderText = " UserID "   />    
11                         < asp:BoundField DataField = " C_Name "  HeaderText = " 中文名字 "    />    
12                         < asp:BoundField DataField = " E_Name "  HeaderText = " 英文名字 "    />    
13                         < asp:BoundField DataField = " QQ "   HeaderText = " QQ "   />    
14                         < asp:BoundField DataField = " UpdataDate "  HeaderText = " 更新时间 "   />    
15                     Columns >    
16                     < RowStyle HorizontalAlign = " Center "   />      
17                     < PagerStyle HorizontalAlign = " Right "   />    
18                 asp:GridView >    
19              td >    
20          tr >           
21   table >    
   

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12639172/viewspace-621635/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/12639172/viewspace-621635/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值