如何根据条件更改列的单元格颜色

时间:2016-06-19 06:20:42

标签: html html-table background-color dynamic-columns

我想根据If(成就> 95%)这样的条件改变我的成就专栏的颜色,它会在单元格中显示绿色。如何做? 我的aspx代码:

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

代码背后:

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>");
            }
        }

0 个答案:

没有答案