Introduction:
In this article I will show you
that how you can change the color of the GridView row by attaching the
onmouseover event to the rows. The code shown below will work for the GridView
control if the alternate item color is the same as the row color.
Attaching the Style to the
GridView control:
Since, I need to attach a color to
every row of the GridView control the best place for this is the
GridView_RowDataBound event which is fired when a row is bound to the GridView
control. Let's see the GridView_RowDataBound event:
|
protected
void
GridView1_RowDataBound(object
sender, GridViewRowEventArgs
e) {
if
(e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover",
"this.style.backgroundColor='blue'");
e.Row.Attributes.Add("onmouseout",
"this.style.backgroundColor='white'");
}
} |
And this is it. Now when you move your mouse
over the GridView row the row will highlight and when you move your mouse away
from the row the row will change to its original color.
I hope you liked this article, happy coding!
| If you are one of the
thousands that visit GridViewGuy for your .NET articles and resources, you
might be interested in making a donation. Extra cash helps pay for the
hosting services and speed things up
around here, and makes this website possible.
Make a Donation
Once, again thank you very much and
remember its because of you FINE people that this website
is up and running. |
|
Export Button is a custom control that let's you export your
DataGrid or TextBox data to several different formats. The
control is extremely easy to use and also exposes design time features. In
this article I will discuss some of the features of the Export Button and
how it benefits the developer.
BUY IT
NOW |