Saturday, March 22, 2008

Highlight a Row in GridView without a postback using ASP.NET and JavaScript

Add "OnRowCreated" event to the GridView:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID" DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" OnRowCreated="GridView1_RowCreated">
 
...
 
</asp:GridView>

The event code:

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
    e.Row.Attributes.Add("onMouseOver", "this.style.background='#eeff00'");
    e.Row.Attributes.Add("onMouseOut", "this.style.background='#ffffff'");       
}
Source

No comments:

Post a Comment