We help IT Professionals succeed at work.

GRIDVIEW CELL FONT COLOR BASED ON CONDITION

BOEING39
BOEING39 asked
on
606 Views
Last Modified: 2012-02-13
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
Comment
Watch Question

Commented:
using System.Drawing;

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

Commented:
using System.Drawing;

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

Commented:
or

this.dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Red;

Commented:
e.Row.ForeColor=Color.Red;
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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;
              }

Author

Commented:
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?

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.