The following JavaScript can do the trick, please note this also works well if you have set the AlternatingRowStyle of the GridView.
function highlight(tableRow, active) {
if (active) {
tableRow.originalstyle = tableRow.style.backgroundColor;
tableRow.style.backgroundColor = '#cfc';
}
else {
tableRow.style.backgroundColor = tableRow.originalstyle;
}
}
Now we can drag a GridView to the page and selected a valid data source. In this demo, I use the Order table in Northwind database. In order to highlight the row on mouse hover, we need to add some custom JavaScript code to onmouseover and onmouseout event handlers of the rows of our GridView. In codehind we have:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes["onmouseover"] = "highlight(this, true);this.style.cursor = 'pointer'";
e.Row.Attributes["onmouseout"] = "highlight(this, false);";
}
Run the application, you will see the result as the screenshot below: