Home > ASP.Net > Conditionally changing a GridView row background or CSS stylesheet

Conditionally changing a GridView row background or CSS stylesheet


Hi all ,

try this example to Conditionally changing a gridview row background or css stylesheet

In GridView RowDataBound Event add the following code for Rows that i want to change background according to condition.


protected void Grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
 if (e.Row.RowType == DataControlRowType.DataRow)
 {
 DateTime? engineerEnd =(DateTime?)Grid.DataKeys[e.Row.RowIndex]["EngineerEnd"];
 bool completed =(bool)Grid.DataKeys[e.Row.RowIndex]["Competed"];

 if (engineerEnd != null && completed == true)
 {
 e.Row.CssClass = "GridViewAdditional";
 }
}

Hope this helps

Good Luck.

Advertisements
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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: