This is a migrated thread and some comments may be shown as answers.

Conditional formating... if less than ...

1 Answer 121 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Krzysztof
Top achievements
Rank 1
Krzysztof asked on 28 Jul 2009, 10:00 AM
Hello Dear Experts. :)
I would like to set the conditional formatting from the code for one column.
The row should change color when the value in column (type datetime) subtracted from the results of today's date is less than 1 month.
Is there any possibility to do this? Or do I have to subtract the date using sql, and select as an additional value?

Best Regards
Krzysztof

1 Answer, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 28 Jul 2009, 01:03 PM
Hi Krzysztof,

Yes, it is possible to set the conditional formatting by code. However, it can't support such complex conditions. A better solution is to handle the CellFormatting event. So here is a sample:

void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) 
    GridDateTimeCellElement cell = e.CellElement as GridDateTimeCellElement; 
    if (cell != null
    { 
        if (DateTime.Now.Subtract((DateTime)cell.Value).Days < 30) 
        { 
            e.CellElement.BackColor = Color.Yellow; 
            e.CellElement.GradientStyle = GradientStyles.Solid; 
            e.CellElement.DrawFill = true
        } 
        else 
        { 
            e.CellElement.DrawFill = false
        } 
    } 

I hope this helps. Should you have any questions, don't hesitate to write us back.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Krzysztof
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or