Suppose,we have a Gridview called grid_project_details as below:-
<asp:GridView ID = "grid_project_details" runat = "server"
OnRowCreated = "grid_project_details_RowCreated">
</asp:GridView>
Now in the
OnRowCreated event we have to write below code:-
protectedvoid grid_project_details_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//On Mouse Over Highlight Row set row color to yellow
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='yellow'");
//On Mouse out reset girdview row color based on our alternate row color
if (e.Row.RowIndex % 2 == 0)
{
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='lightyellow'");
}
else
{
//set white color as default color
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");
}
}
}