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

ConditionalFormatting with DateTime

2 Answers 240 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ricardo Cardoso
Top achievements
Rank 1
Ricardo Cardoso asked on 22 Feb 2008, 05:55 PM
Hi,

I need to use conditional formatting on a report that one field is a DateTime, the condition must be activated when this field take a value less or equal that another DateTime.

But the filters works with String only, how cold I make a filter work with DateTime?

Exemple of my code:
[code]
FormattingRule formAtraso = new FormattingRule();
rule.Filters.Add(new Filter("=Date", FilterOperator.LessOrEqual, AnotherDateTime.ToString()));
rule.Style.Color = Color.Red;
detail.ConditionalFormatting.Add(rule);
[/code]

2 Answers, 1 is accepted

Sort by
0
Hrisi
Telerik team
answered on 26 Feb 2008, 03:47 PM
Hi Ricardo Cardoso,

As you already notice filter constructor accept strings as arguments. But, these strings are expressions and they are evaluated during report processing. In your example AnotherDateTime.ToString() is a string constant in the expression context and therefore is evaluated to string. But the left side "=Date" most probably is evaluated to DateTime in case your data field Date is a DataTime field. You have two possibilities to force evaluation of the right side expression to DateTime:

write it as "=#" +
AnotherDateTime.ToString() + "#"
or as "=CDate(\"" + AnotherDateTime.ToString() + "\")"

You can see what code is generated by editing Expressions for Conditional Formatting in the VS2005 Designer. More information you can find in "Using Expressions" in our documentation where most of the functions are described.

Greetings,
Hrisi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Ricardo Cardoso
Top achievements
Rank 1
answered on 27 Feb 2008, 01:26 PM
Thanks Hrisi!

The article "Using Expressions" helps much!
Tags
General Discussions
Asked by
Ricardo Cardoso
Top achievements
Rank 1
Answers by
Hrisi
Telerik team
Ricardo Cardoso
Top achievements
Rank 1
Share this question
or