using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
/// <summary>
/// Summary description for HoverGridView
/// </summary>
namespace Roboblob.WebControls
{
[ToolboxData("<{0}:HoverGridView runat=server></{0}:HoverGridView>")]
public class HoverGridView : System.Web.UI.WebControls.GridView
{
public bool MouseHoverRowHighlightEnabled
{
get
{
if (ViewState["MouseHoverRowHighlightEnabled"] != null)
return (bool)ViewState["MouseHoverRowHighlightEnabled"];
else
return false;
}
set { ViewState["MouseHoverRowHighlightEnabled"] = value; }
}
public Color RowHighlightColor
{
get
{
if (ViewState["RowHighlightColor"] != null)
return (Color)ViewState["RowHighlightColor"];
else
{
// default color
return Color.Yellow;
}
}
set { ViewState["RowHighlightColor"] = value; }
}
protected override void OnRowCreated(GridViewRowEventArgs e)
{
base.OnRowCreated(e);
if (MouseHoverRowHighlightEnabled)
{
// only apply changes if its DataRow
if (e.Row.RowType == DataControlRowType.DataRow)
{
// when mouse is over the row, save original color to new attribute
// and change it to highlight yellow color
e.Row.Attributes.Add("onmouseover",
string.Format("this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='{0}'",
ColorTranslator.ToHtml(RowHighlightColor)));
// when mouse leaves the row, change the bg color to its original value
e.Row.Attributes.Add("onmouseout",
"this.style.backgroundColor=this.originalstyle;");
}
}
}
}
}