Hello All,
I am using a C# condition that changes the row backcolor of a Gridview based on the scheduled time value(TIMESTAMP ). I am new to C# and could use some help with my code. Thanks!
I am using a C# condition that changes the row backcolor of a Gridview based on the scheduled time value(TIMESTAMP ). I am new to C# and could use some help with my code. Thanks!
Code:
DateTime data = DateTime.Now; //will give time for today
protected void grid_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
if((DateTime.Now - DateTime.Parse((e.Row.DataItem as DataRowView)["scheduledTime "])).TotalMinutes<=15)
e.Row.BackColor = System.Drawing.Color.Red;
else if ((DateTime.Now - DateTime.Parse((e.Row.DataItem as DataRowView)["scheduledTime "])).TotalMinutes >15<=30)
e.Row.BackColor = System.Drawing.Color.yellow;
else if ((DateTime.Now - DateTime.Parse((e.Row.DataItem as DataRowView)["scheduledTime "])).TotalMinutes >30<120)
e.Row.BackColor = System.Drawing.Color.green
}
}
Comment