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

text box format not working

4 Answers 608 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 02 Oct 2009, 06:32 PM
I have a text box that I need to format as a date field and display without the time (hh:mm....).  No matter what I do, it's not formatting correctly and still prints the time along with the date...

I am doing the following statement:


dfImageDate.Value = String.Format (Convert.ToString(JailImage[0].Idate), "{0:d}");

The text box also has a "format" set to {0:d}.

Neither works,  Thanks in advance for your help

4 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 05 Oct 2009, 08:11 AM
Hello Ryan,

The only reason why formatting to DateTime would not work is if the actual field value is not dateTime but string. Please check your field datatype - it should be Date.
If it is date, then the expression in the TextBox should be something like this: = Fields.MyDateTimeField and not {Fields.MyDateTimeField}, which is embedded expression and would be evaluated as string i.e. you not applicable for datetime formatting.

Greetings,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ryan
Top achievements
Rank 1
answered on 05 Oct 2009, 12:16 PM
I am new to telerik, so I'm a little confussed by your answer.  When you say "actual field value ", are you referring to what I am pulling from the database to set the objects value to?  If that's the case, yes, JailImage[0].Idate does represent a datetime column in Oracle.  The "Value" field for the textbox is not set to anything at design time.  At runtime, I set the textboxes values after instantiating a new OpenAccess object that holds the values.  The datasource for the report is not set to this object though.  Is there somewhere on the textbox control that I need to set it to be a datetime field? other than the format?

Thanks again for your help,
Ryan
0
Steve
Telerik team
answered on 05 Oct 2009, 01:19 PM
Hi Ryan,

This is not specific to Telerik Reporting. Looking at your code:

dfImageDate.Value = String.Format (Convert.ToString(JailImage[0].Idate), "{0:d}");

You're converting the date to string and as explained in previous post, you cannot apply DateTime format to a string value.

You can try the same code outside Telerik Reports to see that it would not work as you expect. Setting the formatting option of the textbox is enough if it is bound to a datetime column i.e.

dfImageDate.Value = "= Fields.MyDateTimeField" and the Format property is set to {0:d}.


Greetings,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ryan
Top achievements
Rank 1
answered on 05 Oct 2009, 01:59 PM
Thank you for your quick reply.  When I do the following:

 dfImageDate.Value = "=Fields.JailImage[0].Idate";

The report prints the error in red (An error occurred....) for the value of the textbox.

When I walk through, the JailImage[0].Idate evaluates to {1/2/2009 12:00:00 AM}.

I know when you set the datasource to something (this.datasource = object), the "=Fields." works, but what about when you need to set the textbox to a value other than a datasource?

Thanks, Ryan
Tags
General Discussions
Asked by
Ryan
Top achievements
Rank 1
Answers by
Steve
Telerik team
Ryan
Top achievements
Rank 1
Share this question
or