By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,773 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,773 IT Pros & Developers. It's quick & easy.

GridView coloring on client side

P: n/a
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

--
Regards,
Inna Stetsyak aka InK_
Apr 15 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"InK_" <in**@ukrpost.net> wrote in message
news:OS**************@TK2MSFTNGP05.phx.gbl...
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

--
Regards,
Inna Stetsyak aka InK_

Apr 15 '06 #2

P: n/a
//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

--
( OHM ) - One Handed Man
AKA Terry Burns - http://TrainingOn.net
"InK_" <in**@ukrpost.net> wrote in message
news:OS**************@TK2MSFTNGP05.phx.gbl...
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

--
Regards,
Inna Stetsyak aka InK_

Apr 15 '06 #3

P: n/a
Thanks a lot for help.
It works now.

--
Regards,
Inna Stetsyak aka InK_

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:eA**************@TK2MSFTNGP04.phx.gbl...
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)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"InK_" <in**@ukrpost.net> wrote in message
news:OS**************@TK2MSFTNGP05.phx.gbl...
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

--
Regards,
Inna Stetsyak aka InK_



Apr 15 '06 #4

P: n/a
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:).

--
Regards,
Inna Stetsyak aka InK_

"OHM ( One Handed Man )" <me@mine.com> wrote in message
news:uj**************@TK2MSFTNGP05.phx.gbl...
//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

--
( OHM ) - One Handed Man
AKA Terry Burns - http://TrainingOn.net
"InK_" <in**@ukrpost.net> wrote in message
news:OS**************@TK2MSFTNGP05.phx.gbl...
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

--
Regards,
Inna Stetsyak aka InK_



Apr 15 '06 #5

P: n/a
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.

--
( OHM ) - One Handed Man
AKA Terry Burns - http://TrainingOn.net
"InK_" <in**@ukrpost.net> wrote in message
news:uI**************@TK2MSFTNGP02.phx.gbl...
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:).

--
Regards,
Inna Stetsyak aka InK_

"OHM ( One Handed Man )" <me@mine.com> wrote in message
news:uj**************@TK2MSFTNGP05.phx.gbl...
//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

--
( OHM ) - One Handed Man
AKA Terry Burns - http://TrainingOn.net
"InK_" <in**@ukrpost.net> wrote in message
news:OS**************@TK2MSFTNGP05.phx.gbl...
> 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
>
> --
> Regards,
> Inna Stetsyak aka InK_
>
>



Apr 15 '06 #6

P: n/a
Sure, just FYI

--
Regards,
Inna Stetsyak aka InK_

"OHM ( One Handed Man )" <me@mine.com> wrote in message
news:uy*************@TK2MSFTNGP05.phx.gbl...
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.

--
( OHM ) - One Handed Man
AKA Terry Burns - http://TrainingOn.net
"InK_" <in**@ukrpost.net> wrote in message
news:uI**************@TK2MSFTNGP02.phx.gbl...
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:).

--
Regards,
Inna Stetsyak aka InK_

"OHM ( One Handed Man )" <me@mine.com> wrote in message
news:uj**************@TK2MSFTNGP05.phx.gbl...
//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

--
( OHM ) - One Handed Man
AKA Terry Burns - http://TrainingOn.net
"InK_" <in**@ukrpost.net> wrote in message
news:OS**************@TK2MSFTNGP05.phx.gbl...
> 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
>
> --
> Regards,
> Inna Stetsyak aka InK_
>
>




Apr 15 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.