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

来源:互联网 发布:python socket bind 编辑:程序博客网 时间:2024/06/10 17:32
在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");

              }

     }

}



本文引用通告地址: http://blog.csdn.net/yx10/services/trackbacks/417582.aspx