Using the report writer Q2 2008, I have the following text box which works when there is a value in the date, but errors when there is not.
="Change Date " + Fields.ChangeDt.ToString("dd MMM yyyy")
I would like to make the entire textbox invisible, or have it ignored when the value ChangeDt is null or empty.
How can this be done?
Thanks
Mike Thomas
="Change Date " + Fields.ChangeDt.ToString("dd MMM yyyy")
I would like to make the entire textbox invisible, or have it ignored when the value ChangeDt is null or empty.
How can this be done?
Thanks
Mike Thomas
4 Answers, 1 is accepted
0
Hi Mike,
You can use the built-in IsNull() or IIf() functions to handle such case.
Kind regards,
Steve
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
You can use the built-in IsNull() or IIf() functions to handle such case.
Kind regards,
Steve
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

Mike
Top achievements
Rank 1
answered on 18 Nov 2008, 05:43 PM
Thanks Steve,
My real problem is a little different than what I had thought. In the example below, it looks like the ToString() method is called whether the date value, here ChangeDt, is null or not.
When ChangeDt is not null, the line below, in the value property for the text box works fine. When the value is null, the report displays an error " #ERROR# The expression contains unidentified function call ToString()". Apparently the ToString() method is called whether ChangeDt is null or not.
=IIF(IsNull(Fields.ChangeDt,#01/01/1949#)< #01/01/1950# ,"","Change Date: " + Fields.ChangeDt.ToString("dd MMM yyyy"))
In other words, how to format the date, either as "dd MMM yyyy" or {0:dd MMM yyyy} only when the date value is not null.
Thanks
Mike Thomas
My real problem is a little different than what I had thought. In the example below, it looks like the ToString() method is called whether the date value, here ChangeDt, is null or not.
When ChangeDt is not null, the line below, in the value property for the text box works fine. When the value is null, the report displays an error " #ERROR# The expression contains unidentified function call ToString()". Apparently the ToString() method is called whether ChangeDt is null or not.
=IIF(IsNull(Fields.ChangeDt,#01/01/1949#)< #01/01/1950# ,"","Change Date: " + Fields.ChangeDt.ToString("dd MMM yyyy"))
In other words, how to format the date, either as "dd MMM yyyy" or {0:dd MMM yyyy} only when the date value is not null.
Thanks
Mike Thomas
0
Accepted
Hello Mike,
You can handle this in several ways. The easiest would be to use the Format property of the textbox item, select datetime and enter your specific formatting: {0:dd MMM yyyy}.
Another approach is using custom user function:
public static object FormatMyDate(object value)
{
if (value == null || value == DBNull.Value)
return null;
//if the cast throws exception, there is something wrong with the dataset
DateTime datetime = (DateTime)value;
return datetime.ToString("dd MMM yyyy");
}
and set =FormatMyDate(Fields.SellEndDate) for the expression of the DateTime column.
Regards,
Steve
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
You can handle this in several ways. The easiest would be to use the Format property of the textbox item, select datetime and enter your specific formatting: {0:dd MMM yyyy}.
Another approach is using custom user function:
public static object FormatMyDate(object value)
{
if (value == null || value == DBNull.Value)
return null;
//if the cast throws exception, there is something wrong with the dataset
DateTime datetime = (DateTime)value;
return datetime.ToString("dd MMM yyyy");
}
and set =FormatMyDate(Fields.SellEndDate) for the expression of the DateTime column.
Regards,
Steve
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

Mike
Top achievements
Rank 1
answered on 19 Nov 2008, 04:37 PM
Thanks again Steve - the custom user function was the way to go.
Mike Thomas
Mike Thomas