Link to home
Start Free TrialLog in
Avatar of BOEING39
BOEING39

asked on

GRIDVIEW CELL FONT COLOR BASED ON CONDITION

I have the following code behind where I need to change the font color based on a condition of column14 being "High Priority" where the Font is changed to red.



else if (e.Row.Cells[14].Text == "High Priority")
            {

                e.Row.BackColor = System.Drawing.Color.LightSkyBlue ;

            }
Home1All.aspx.cs
Home1All.aspx
Avatar of ukerandi
ukerandi
Flag of United Kingdom of Great Britain and Northern Ireland image

using System.Drawing;

    eRows[rowNr].Cells[14].ForeColor = Color.Red;
using System.Drawing;

    e.Rows[rowNr].Cells[14].ForeColor = Color.Red;
or

this.dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Red;
e.Row.ForeColor=Color.Red;
ASKER CERTIFIED SOLUTION
Avatar of ukerandi
ukerandi
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BOEING39
BOEING39

ASKER

Tried the different variations listed.   No joy.    


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
            if (e.Row.Cells[14].Text == "AOG" || e.Row.Cells[14].Equals(DBNull.Value))
            {
                e.Row.BackColor = System.Drawing.Color.Red;
            }

            else if (e.Row.Cells[14].Text == "ETOPS - Working")
            {
                e.Row.BackColor = System.Drawing.Color.Yellow;
            }

            else if (e.Row.Cells[14].Text == "AOG - R/T")
            {
                e.Row.BackColor = System.Drawing.Color.Tomato;
            }

            else if (e.Row.Cells[14].Text == "High Priority")
            {

                e.Row.BackColor = System.Drawing.Color.LightSkyBlue ;

            }
            else if (e.Row.Cells[14].Text == "SOS - Working")
            {

                e.Row.BackColor = System.Drawing.Color.Orange;

            }
            else if (e.Row.Cells[14].Text == "Working Spare")
            {

                e.Row.BackColor = System.Drawing.Color.Aquamarine;

            }
            else if (e.Row.Cells[14].Text == "AOG - Vendor")
            {

                e.Row.BackColor = System.Drawing.Color.Orange;

            }
            else if (e.Row.Cells[14].Text == "AOG-Sched/Work Required")
            {

                e.Row.BackColor = System.Drawing.Color.Crimson;
            }
            else if (e.Row.Cells[14].Text == "AOG-Sched/Work Elective")
            {

                e.Row.BackColor = System.Drawing.Color.Coral;
            }
            else if (e.Row.Cells[14].Text == "ETOPS Fly Day")
            {

                e.Row.BackColor = System.Drawing.Color.Fuchsia;
            }  
            else if (e.Row.Cells[14].Text == "Ready Spare")
            {

                e.Row.BackColor = System.Drawing.Color.Lime;
            }  
            else if (e.Row.Cells[14].Text == "Ready Spare - A/C Hooked - WU-cw")
            {

                e.Row.BackColor = System.Drawing.Color.Lime;
            }
            else if (e.Row.Cells[14].Text == "Ready Spare - Needs WU ck")
            {

                e.Row.BackColor = System.Drawing.Color.Lime;
            }  
            else if (e.Row.Cells[14].Text == "Ready Spare - A/C Hooked - Needs WU")
            {

                e.Row.BackColor = System.Drawing.Color.Lime;
            }  
            else if (e.Row.Cells[14].Text == "Status Ready Spare - Needs WU-ck")
            {

                e.Row.BackColor = System.Drawing.Color.Lime;
                 }  
                  else if (e.Row.Cells[14].Text == "High Priority")
            {
           
                 e.Row.ForeColor = Color.Red;
              }
Used other option listed above, without  "else if"   and used "if" works great.   I would also like to change this to bold when the condition is met.   Any ideas on that?