In my asp.net project, I am looking to dynamically change the text color of a table cell based on a certain parameter. Here's an example scenario:
TableCell dataCell = new TableCell();
foreach (var o in results)
{
TimeSpan timeDiff = (DateTime.Now - o.time);
if (timeDiff.TotalSeconds < 60.0)
{
//Display in green color
dataCell.Text += o.name;
//I attempted using string.Format("<p style=\"color:green\">{0}</p>", o.name); but it didn't work.
}
else
{
//Display in red color
dataCell.Text += o.name;
}
}
TRow.Cells.Add(dataCell);
I specifically require the text to be displayed in a single line which is why <h3>
, <div>
, and <p>
elements do not suit my needs.