GridView Row Color Change On MouseOver
In your code behind, you will need to add a handler for this event. For my example, I’m using alternating background colors on rows (which you should do too, it makes things so much more readable). This causes me to add a couple extra lines so that I make sure I’m setting my rows back to the correct color on MouseOut.
protected void gvNews_OnRowCreated(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
if (e.Row.RowState == DataControlRowState.Alternate)
That’s all there is to it. If you want to see this in action, check out the news section on the main page here.
There is room for improvement here… you could assign a CSS class instead of hard coding the colors. I believe there is also a way you could also get the background color that is assigned in the RowStyle/AlternatingRowStyle section. That would make this much more portable.
This article has been view 21364 times.