开发者

how to preserve the orgianl backgroundColor when hovering?

开发者 https://www.devze.com 2023-04-09 18:32 出处:网络
below is the code that works fine but the only problem i have is : its overriding the alternative row with backgroundColor=\'white\' how can i have my orginal alternative color when onmouseout ?

below is the code that works fine but the only problem i have is : its overriding the alternative row with backgroundColor='white' how can i have my orginal alternative color when onmouseout ?

<AlternatingRowStyle BackColor="#DEEEE9" Fon开发者_开发百科t-Size="8pt" />

if (e.Row.RowType == DataControlRowType.DataRow)
{
    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#C2D69B'");
    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");
    e.Row.Attributes.Add("style", "cursor:pointer;");
}


You can specify what color exactly should be restored on onmouseout:

if (e.Row.RowType == DataControlRowType.DataRow)
{
    string bgcolor = "white"
    if (e.Row.RowState == DataControlRowState.Alternate)
    {
       bgcolor = "#DEEEE9";
    }

    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#C2D69B'");
    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='" + bgcolor  + "'");
    e.Row.Attributes.Add("style", "cursor:pointer;");
}


I don't get it, why not just take out the "e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");" and set it to the color of the original alternate???


instead of specifying a specific color, use the hover css attributes. See: http://www.codeproject.com/KB/webforms/MouseHoverUsingCSS.aspx


Try something like this:

var color = "<%=System.Drawing.ColorTranslator.ToHtml(GridView1.AlternatingRowStyle.BackColor)%>";


This works well with much less code. Create a custom attribute in the mouseover before setting the backgroundColor and use it on the mouse out. Works perfectly for alternating row colors.

row.Attributes["onmouseover"] = this.originalstyle=this.style.backgroundColor;this.style.cursor='hand';this.style.backgroundColor='#ffccff';";

row.Attributes["onmouseout"] = "this.style.textDecoration='none';this.style.backgroundColor=this.originalstyle;";
0

精彩评论

暂无评论...
验证码 换一张
取 消