Highlighting Gridview Row on Mouse Over event when Gridview ALTERNATE rows are applied in Asp.Net

Rajesh_Kumar
Posted by Rajesh_Kumar under ASP.NET category on | Points: 40 | Views : 747
Either we can write code on Gridview Rowcreated event or RowDataBound event.

protected void project_grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Highlight Row on Mouse over event
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#F0D8D8'");

//On Mouse out event restore girdview row color based on alternate row color
if (e.Row.RowIndex % 2 == 0)
{
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#F5F5DC'");
}
else
{
//Reset Row Color(White Color)
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
}
}
}

Comments or Responses

Login to post response