Subscribe Now!

Enter your email address:

Thursday, March 3, 2011

Code for How to Highlight Gridview Row on Mouse Over when gridview rows are using alternate row color in Asp.net


In .aspx File declare OnRowCreated eventas follow.
<asp:GridView ID="GridView1" runat="server" OnRowCreated="OnRowCreated">

Following code will explain: 
How to Highlight Gridview which uses alternate row color.

protectedvoid OnRowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        //On Mouse over highlight gridview
        e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ffff00'");

        //On Mouse out restore girdview row color based on alternate row color//Please change this color with your gridview alternate color.if (e.Row.RowIndex % 2 == 0)
        {
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#F7F7DE'");
        }
        else
        {
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
        }
    }
}

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...