change gridview color on mouse out

  • Thread starter Thread starter fredd00
  • Start date Start date
F

fredd00

how can i change the back color on mouse out to the color specified in
the grid view declaration

in the gridview declaration

<AlternatingRowStyle BackColor="#CECECE" />
<RowStyle BackColor="#DEDEDE" />

the RowDataBound (i don't want to have to specify the color code, i
might want to use themes in the future)

protected virtual void RowDataBound(object sender,
GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Alternate)
{
e.Row.Attributes.Add("onmouseout",
string.Format("this.style.backgroundColor='{0}'", "#CECECE"));
}
else
{
e.Row.Attributes.Add("onmouseout",
string.Format("this.style.backgroundColor='{0}'", "#DEDEDE"));
}
e.Row.Attributes.Add("onmouseover",
"this.style.backgroundColor='orange'; this.style.cursor='pointer';");

}
}
 
how can i change the back color on mouse out to the color specified in
the grid view declaration

you can do it using css

..row1
{
background: #CECECE;
}
..row2
{
background: #DEDEDE;
}
..row1:hover, .row2:hover
{
cursor: pointer;
background-color: orange;
}


so, in this case your grid coding should be

<RowStyle CssClass="row1"></RowStyle>
<AlternatingRowStyle CssClass="row2"></AlternatingRowStyle>
 
Back
Top