Subscribe
TechTasks.net

The Blog is Moved to www.TechTasks.net

Change GridView Row Color When MouseOver

Posted by Rajesh Kumar Chekuri on

In .CS file

using System.Data.SqlClient;


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");

con.Open();

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

ds = new DataSet();

da.Fill(ds, "product");

GridView1.DataSource = ds;

GridView1.DataBind();

}

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)

{

string onmouseoverstyle = "this.style.backgroundColor='red'";

string onmouseoutstyle="this.style.backgroundColor = 'white'";

string onmouseclickstyle = "this.style.backgroundColor = '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 );


}

}

}



DESIGN

Bookmark and Share
Change GridView Row Color When MouseOverSocialTwist Tell-a-Friend

0 comments:

Subscribe to: Post Comments (Atom)
Thanks For Visiting