Thursday, October 23, 2008

Highlight GridView rows when condition is true

0 comments 10/23/2008
Sign up to receive our site updates!
Grid view Row display in Different color based on the condition for that we use GridView_RowCreated event.To Style the GridView Row when Mouse over check out Change GridView Row Color When Mouse Over




have a Look at the Code Snippet

C# Code..

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

{

SqlConnection con; DataSet ds; SqlDataAdapter da;

protected void Page_Load(object sender, EventArgs e)

{

con = new SqlConnection("Data Source=TECH-DA98E1DFBA\\SQLEXPRESS;Initial Catalog=tempdb;Integrated Security=True");

con.Open();

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

ds = new DataSet();

da.Fill(ds, "emp");

GridView1.DataSource = ds;

GridView1.DataBind();

}

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)

{

if (e.Row.DataItem != null)

{

DataRowView drv = (DataRowView)e.Row.DataItem;

int sal = int.Parse(drv["sal"].ToString());

if (sal >= 10000)

e.Row.BackColor = Color.LightBlue ;

//Display gridveiw row in diff color whose sal is greaterthan 10,000

}

}

}

}


Your Ad Here

0 comments:

Respects for your's Questions & Opinions

  • Friends
  •  

    Recent Posts

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