checkout here Highlight GridView rows when condition is true
Design..
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");
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 );
}
}
}
0 comments:
Respects for your's Questions & Opinions