Showing posts with label rowdatabound. Show all posts
Showing posts with label rowdatabound. Show all posts

Monday, July 20, 2009

programatically change gridview row background color


//change bgcolor of gridview row based on data
//in this case the data I am testing is in a templatefield that is hidden
//if the data had been added in the last hour, then I apply a certain css class

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DateTime entryDate = Convert.ToDateTime(((DataRowView)e.Row.DataItem)["DtEnter"]);
DateTime nowDate = DateTime.Now;
TimeSpan ts = nowDate.Subtract(entryDate);

if (ts.TotalMinutes <= 60)
{
e.Row.CssClass = "updatedRow";
}
}
}