I need to change the display date format of all the dates in my Dynamic Data app. I'm trying to modify the DateTime field template to always return in short date format ("d"). I don't need globalization or anything sophisticated. Changing the
return Literal1 to return Literal1.ToString("d") gives an error"No overload for method 'ToString' takes 1 arguments".
Jim Foulkrod
Member
11 Points
28 Posts
Change the date format displayed by the DateTime Field Templates
Sep 23, 2011 06:03 PM|LINK
I need to change the display date format of all the dates in my Dynamic Data app. I'm trying to modify the DateTime field template to always return in short date format ("d"). I don't need globalization or anything sophisticated. Changing the return Literal1 to return Literal1.ToString("d") gives an error"No overload for method 'ToString' takes 1 arguments".
Thanks,
Jim
princeG
Star
9612 Points
1602 Posts
Re: Change the date format displayed by the DateTime Field Templates
Sep 23, 2011 06:10 PM|LINK
Because you are converting string into date. that why it is giving error
you need to convert like
Convert.ToDateTime(literal1.Text).ToString("d")
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: Change the date format displayed by the DateTime Field Templates
Sep 23, 2011 08:22 PM|LINK
You will need to do this in the OnDataBinding event of the field template and use the FiledValue property
Literal1.Text = ((DateTime)FieldValue).ToString("d");
Or you can do that using the [DataTypeAttabute on each DataTime field in the metadata.
Always seeking an elegant solution.