<< Click to Display Table of Contents >> GridView - linha sob o mouse destacar cor |
![]() ![]() ![]() |
// evento exclusivo para "acender" onde o mouse está
protected void Grid_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.DataItem != null)
{
string status = DataBinder.Eval(e.Row.DataItem, "status").ToString();
// as duas cores, cinza mais claro e mais escuro, ficam nas var cor e coralt
string cor = "#EEEEEE";
string coralt = "#DCDCDC";
// se o campo "status" for Atual, troca o cor para verde9/
if (status == "Atual")
{
cor = "green";
coralt = cor;
}
if (e.Row.RowState == DataControlRowState.Alternate)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#FFFFE1';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='" + coralt + "';");
}
else
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#FFFFE1';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='" + cor + "';");
}
}
}