Home > ASP.Net > GridView Row Color Change On Mouse Hover

GridView Row Color Change On Mouse Hover

Hi all,

try this example to change Gridview Row Color on MouseHover

1) Open VS 2008 and create a new web site and add new web Page

2) From ToolBox Drag and Drop Gridview control in your ASPX Page

<asp:GridView ID="GridView1" runat="server" OnRowCreated="GridView1_RowCreated"></asp:GridView>

In code behind :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class _Default : System.Web.UI.Page
 SqlConnection con = new SqlConnection("Data Source=Northwind;Integrated Security=true;Initial Catalog=session");
 protected void Page_Load(object sender, EventArgs e)
 if (!IsPostBack)
 protected void BindGridview()
 SqlCommand cmd = new SqlCommand("select * from Customers", con);
 SqlDataAdapter da = new SqlDataAdapter(cmd);
 DataSet ds = new DataSet();
 GridView1.DataSource = ds;

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

Hope this helps

Good Luck.

Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: