CODE TO CHANGE COLOR WHEN MOUSE IS HOVER ON THE GRIDVIEW ROWS:

Debendra256
Posted by Debendra256 under ASP.NET category on | Points: 40 | Views : 444
ADD THE FOLLOWING JAVASCRIPT ON HEAD SECTION

<script type="text/javascript">
var oldgridcolor;
function SetMouseOver(element) {
oldgridcolor = element.style.backgroundColor;
element.style.backgroundColor = 'lightblue';
element.style.cursor = 'pointer';
}
function SetMouseOut(element) {
element.style.backgroundColor = oldgridcolor;
element.style.textDecoration = 'none';

}
</script>


WRITE THE FOLLOWING CODE IN THE GridView1_RowDataBound


protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "javascript:SetMouseOver(this)";
e.Row.Attributes["onmouseout"] = "javascript:SetMouseOut(this)";
}





}


Or you can use the following .cs code also to change color


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onMouseOver", "this.style.backgroundColor = '#F0E68C';");
e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor = 'white';");
}
}

Comments or Responses

Login to post response