GridView coloring on client side

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
 
T

Teemu Keiski

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)
 
O

OHM \( One Handed Man \)

//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
 
I

InK_

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:).
 
O

OHM \( One Handed Man \)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top