Saturday 16 June 2012

Code for How to Highlight Row of Gridview on Mouse Over which doesn't use alternate row color in Asp.net


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

Following code will:
Highlight Gridview which is not using alternate row color.
protectedvoid OnRowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        //On Mouse Over Highlight Row
        e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ffff00'");

        //On Mouse out restore default row color
        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
    }
}

No comments:

Post a Comment