太多了发布下给你节选了一下 namespace prjBaseClass.Controls.DataGrid { using System; using System.Data; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Drawing; using System.ComponentModel; using prjBaseClass.Controls; /// <summary> /// 继承的 DataGrid 封装了鼠标悬停事件与单击选定事件以及底部统计导航栏 /// </summary> public class myDataGrid : DataGrid , IPostBackEventHandler {
再加上 鼠标事件
namespace prjBaseClass.Controls.DataGrid
{
using System;
using System.Data;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.ComponentModel;
using prjBaseClass.Controls; /// <summary>
/// 继承的 DataGrid 封装了鼠标悬停事件与单击选定事件以及底部统计导航栏
/// </summary>
public class myDataGrid : DataGrid , IPostBackEventHandler
{
/// <summary>
/// 鼠标悬停时的行背景颜色 默认为不启用鼠标悬停功能
/// </summary>
public string MouseOverItemBackColor
{
set{
this.strMouseOverItemBackColor = value;
}
}}
if ( this.strMouseOverItemBackColor.Length == 7 )
{
if ( this.strItemBackColor == String.Empty )
{
if ( this.ItemStyle.BackColor.IsEmpty )
this.strItemBackColor = "#FFFFFF";
else
{
if ( this.ItemStyle.BackColor.IsNamedColor)
this.strItemBackColor = this.ItemStyle.BackColor.Name;
else
this.strItemBackColor = "#" + this.ItemStyle.BackColor.Name.Substring( 2 , 6 );
} if ( this.AlternatingItemStyle.BackColor.IsEmpty )
this.strAlternatingItemBackColor = this.strItemBackColor;
else
{
if ( this.AlternatingItemStyle.BackColor.IsNamedColor )
this.strAlternatingItemBackColor = this.AlternatingItemStyle.BackColor.Name;
else
this.strAlternatingItemBackColor = "#" + this.AlternatingItemStyle.BackColor.Name.Substring( 2 , 6 );
}
}
if ( e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
{
e.Item.Attributes.Add("onmouseover","this.style.backgroundColor = '" + this.strMouseOverItemBackColor + "'");
e.Item.Attributes.Add("style","cursor:hand");
if (iItemCount % 2 == 0)
{
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor = '" + this.strItemBackColor + "';");
}
else
{
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor = '" + this.strAlternatingItemBackColor + "';");
}
iItemCount++;
}
}
#endregion