You are here:

C#/Change Datagrid cell color based on cell value

Advertisement


Question
I've a EndDate field and the cell need to be highlighted RED for all EndDate that are less than or equal to todays systemdate(I do code in C#,windows application).
Thanking you

Answer
Hi

Here is the simple sample

//Loop through all rows.
for (int x = 0; x < yourGridName.Rows.Count; x++)
{
  //Change cell colour to Red.
  if (endDate < DateTime.Now)
  {
    //Loop through all cells in that row and change its color.
    for (int y = 0; y < yourGridName.Rows[x].Cells.Count; y++)
    {
         yourGridName.Rows[x].Cells[y].Style.BackColor =
         System.Drawing.Color.Red;
    }
  }
}

Happy Programming!!

-Srini

C#

All Answers


Answers by Expert:


Ask Experts

Volunteer


Srini Nagarajan

Expertise

can answer any kind of questions in ASP.NET, C#, VB.NET, ASP, SharePoint 2007, Coldfusion, Powerbuilder 7.00 / 8.00, JAVA servlets, MS SQL 2000 / MSSQL7, Sybase

Experience

Contact me if you need any custom development on ASP.NET, ASP, Coldfusion, Powerbuilder

©2012 About.com, a part of The New York Times Company. All rights reserved.