blog.mha.dk
The on-line blog of Michael Holm Andersen

MouseOver colour in GridView control

Monday, 16 October 2006 17:59 by mha

Ever wanted to have a different colour for the 'active' row in the GridView?

All you have to do is place the code below in the grids RowDataBound event. The code below asume we're using 'AlternatingRowStyle' to make the BackColor different for even/odd rows.

if (e.Row.RowType == DataControlRowType.DataRow)
   {
      
if (e.Row.RowIndex % 2 == 0)
      {
         e.Row.Attributes.Add(
"onmouseover", "this.style.backgroundColor='#D8D8D8'");
         e.Row.Attributes.Add(
"onmouseout", "this.style.backgroundColor='#FFFFFF'");
      } 
else
     
{
         e.Row.Attributes.Add(
"onmouseover", "this.style.backgroundColor='#D8D8D8'");
         e.Row.Attributes.Add(
"onmouseout", "this.style.backgroundColor='#F7F6F3'");
      }
}

Comments are closed