About the author

Miron Abramson
Software Engineer,
CTO at PixeliT
and .NET addicted for long time.
Open source projects:
MbCompression - Compression library

Recent comments



The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2018

Creative Commons License

Blog Flux Directory
Technology Blogs - Blog Top Sites

Hightlight rows on OnMoueover event in GridView

A nice and simple functionality can make big visual different.

For example: Highlight rows on OnMouseOver event in GridView will make it much nicer. All you need to do is to execute the following method on the 'OnRowDataBound' event  in the Grid:

protected void HighLightRow(GridViewRowEventArgs e, string OriginalColor, string OnMouseOverColor,
    string OriginalFontColor, string onMouseOverFontColor)
    if (e.Row.RowType == DataControlRowType.DataRow)
        e.Row.Attributes.Add("onmouseover", "this.style.background='" + OnMouseOverColor +
            "';this.style.color='" + onMouseOverFontColor + "';");
        e.Row.Attributes.Add("onmouseout", "this.style.background='" + OriginalColor +
            "';this.style.color='" + OriginalFontColor + "';");

Ofcourse you can play with it and make it even nicer.

Implementation:  Drop the method above in your page, BasePage or whereevr, add an event handler 'OnRowDataBound' to your  GidView and call the HighLightRow method from this event. For example:

In the aspx:
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView_RowDataBound"> ...

in the code behind:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
       HighLightRow(e, "#86CCF7", "#C0E2F7","Black","Black");

Currently rated 4.5 by 4 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by Miron on Wednesday, October 17, 2007 10:31 AM
Permalink | Comments (3) | Post RSSRSS comment feed

Related posts



Monday, November 26, 2007 2:04 AM


Pingback from techtoolblog.com

The Daily Find #5 - TechToolBlog


Friday, February 15, 2008 7:38 AM


Hi Miron

It was interesting to see this code. I have one question - how do you attach it to the gridview control on the form? If you have time, let me know.


Miron Abramson il

Friday, February 15, 2008 8:03 AM

Miron Abramson

See the updated post. I added implementation example.