GridView coloring on client side

  • Thread starter Thread starter InK_
  • Start date Start date
I

InK_

Hi, All!

I need to accomplish such functionality:
A data row should be highlighted with the other color if cursor is over it.

I also have the old code from asp which uses
<tr onmouseover="colorrow(this,'#EEEEEE');"
onmouseout="colorrow(this,'#FFFFFF');">

for every row of a table.

What can I do to achieve the same for GridView or may be I should use
something else?

Thanks
 
Hi,

you can do it in RowCreated event of GridView by adding those as attributes
to the row

Something like (the code is untested)

Protected Sub grid1_RowCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles grid1.RowCreated
If e.Row.RowState = DataControlRowState.Alternate OrElse
e.Row.RowState = DataControlRowState.Normal Then
e.Row.Attributes("onmouseover") = "colorrow(this,'#EEEEEE');"
e.Row.Attributes("onmouseout") = "colorrow(this,'#FFFFFF');"
End If
End Sub

(or just check RowType for being a DataRow and do it in RowDataBound)
 
//In the itemDataBound Event for the DataGrid

For Each TableCell As TableCell In e.Item.Cells
TableCell.Attributes.Add("onmouseOver", "go(this,'red');")
TableCell.Attributes.Add("onmouseOut", "go(this,'white');")
Next


//Then just add the javascript function in the html

function go( item , col)
{
item.style.backgroundColor=col;
}

HTH
 
Thanks for help.
For sure it will work with DataGrid but I needed the same for GridView.
Look at the solution proposed by Teemu Keiski's. It works for me:).
 
The principal is the same. Its only the event names which are different and
I dont need to look at Teemu's example as it's not me that needs the help.
 
Back
Top