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

Make Textbox Invisible on Null or Empty Value

4 Answers 1090 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 17 Nov 2008, 10:49 PM
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

4 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 18 Nov 2008, 03:58 PM
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.
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
0
Accepted
Steve
Telerik team
answered on 19 Nov 2008, 03:07 PM
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.
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
Tags
General Discussions
Asked by
Mike
Top achievements
Rank 1
Answers by
Steve
Telerik team
Mike
Top achievements
Rank 1
Share this question
or