当前位置:编程学习 > C#/ASP.NET >>

在DataGrid中,使鼠标到达的行和列显示不同的颜色

答案:
如下图所示:

核心代码:

private void grdCustomer_ItemDataBound(object sender,

         System.Web.UI.WebControls.DataGridItemEventArgs e)

{

     if(e.Item.ItemType == ListItemType.AlternatingItem ||

              e.Item.ItemType == ListItemType.Item )

     {

e.Item.Attributes.Add("onmouseover", "this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#C8F7FF'");

        e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor");

          for (int i = 0; i< grdCustomer.Columns.Count; i++ )

              {

                   e.Item.Cells[i].Attributes.Add("onmouseover",

          "this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#99ccff'");

                   e.Item.Cells[i].Attributes.Add(

                       "onmouseout", "this.style.backgroundColor=this.oldcolor");

              }

     }

}


上一个:从SQL Server中读写大数据列
下一个:悲观观定SQL Server和Oracle

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,