How to change the column's cell Color based on condition

Shahanaakter
Posted by Shahanaakter under ASP.NET category on | Points: 40 | Views : 313
want to change color of my Achievement column based on condition like If(Achievement>95%) it will show green color in cell.How to to do it?
My aspx code:

<asp:PlaceHolder ID = "PlaceHolder1" runat="server"/>

Code Behind:

DataSet ds = new DataSet();
ds = new ProcessedData().LoadAllData(Convert.ToInt32(ddlYear.SelectedValue), Convert.ToInt32(ddlMonth.SelectedValue), Convert.ToInt32(ddlDepot.SelectedValue), ModuleID);

StringBuilder strResults = new StringBuilder();

strResults.Append("<table border='1' style='width:628px'>");

strResults.Append("<tr style='background-color:gray; color: White;'><th>Description</th><th>Target</th><th>Actual</th><th>Achievement</th></tr>");

if (!object.Equals(ds.Tables[0], null))
{
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
strResults.Append("<tr style='color: black;'>");
strResults.Append("<td>" + ds.Tables[0].Rows[i]["Description"] + "</td>");
strResults.Append("<td>" + ds.Tables[0].Rows[i]["Target"] + "</td>");
strResults.Append("<td>" + ds.Tables[0].Rows[i]["Actual"] + "</td>");
strResults.Append("<td>" + ds.Tables[0].Rows[i]["Achievement"] + "</td>");
strResults.Append("</tr>");
}

strResults.Append("</table>");
PlaceHolder1.Controls.Add(new Literal { Text = strResults.ToString() });
}
else
{
strResults.Append("<tr>");
strResults.Append("<td align='center' colspan='4'>There is no Record.</td>");
strResults.Append("</tr>");
}
}

Comments or Responses

Login to post response