Saturday, December 6, 2008

Change GridView Row Color When MouseOver

0 comments 12/06/2008
Sign up to receive our site updates!
Grid view Row display in Different color when Mouse Over for that we use GridView_RowCreated event.To Style the GridView Row based on the condition
checkout here Highlight GridView rows when condition is true


have a Look at the Code Snippet

C# Code..

public partial class _Default : System.Web.UI.Page


SqlConnection con; SqlDataAdapter da; SqlCommand cmd; DataSet ds;

protected void Page_Load(object sender, EventArgs e)


con = new SqlConnection("server=FOCALPOI-392A7D\\SQLEXPRESS;user id=raji;password=chekuri;database=raji");


da = new SqlDataAdapter("select * from product", con);

ds = new DataSet();

da.Fill(ds, "product");

GridView1.DataSource = ds;



protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)


string onmouseoverstyle = "'red'";

string onmouseoutstyle=" = 'white'";

string onmouseclickstyle = " = 'lightgreen'";

if (e.Row.RowType == DataControlRowType.DataRow)


//adds events to GridView row

e.Row.Attributes.Add("onmouseover", onmouseoverstyle);

e.Row.Attributes.Add("onmouseout", onmouseoutstyle);

e.Row.Attributes.Add("onclick", onmouseclickstyle );




Your Ad Here


Respects for your's Questions & Opinions

  • Friends

    Recent Posts

    Copyright 2008 All Rights Reserved Tech Tasks Template by Rajesh Kumar Chekuri