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

DataFormatString with General Date Short Time ("g") Format Specifier doesn't work

4 Answers 1231 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Moe Greene
Top achievements
Rank 1
Moe Greene asked on 01 Dec 2010, 11:23 AM

Hi,

I have this column in my grid:

<Telerik:GridBoundColumn UniqueName="OrderDate" DataField="OrderDate" DataFormatString="{0:g}" DataType=System.DateTime" />

According to http://msdn.microsoft.com/en-us/library/az4se3k1.aspx the "g" standard format specifier represents a combination of the short date ("d") and short time ("t") patterns, separated by a space. It should render (in my locale) as "yyyy-MM-dd hh:mm", but the column wrongfully includes the seconds in the rendered text (it is rendered like this: "yyyy-MM-dd hh:mm:ss)". What am I doing wrong?

TIA.

4 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 01 Dec 2010, 12:50 PM
Hi Moe,

Seems to work OK at my site. Attaching a test page to demonstrate.

Kind regards,
Veli
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Princy
Top achievements
Rank 2
answered on 01 Dec 2010, 12:54 PM
Hello,

I have tried the same code and that didn't work in edit mode.DataFormatString is not applied for the controls generated for Edit/Insert mode so you need to set it explicitly.I have found a forum which discusses the similar scenario.
http://www.telerik.com/community/forums/aspnet-ajax/grid/185727-dataformatstring-in-edit-mode.aspx#835013

If this is not the issue,another suggession is to give the DataFormatString string as follows.

aspx:
  <telerik:GridBoundColumn UniqueName="HireDate" DataFormatString="{0:yyyy-MM-dd hh:mm tt}" DataField="HireDate"
DataType="System.DateTime" />

Thanks,
Princy.
0
Moe Greene
Top achievements
Rank 1
answered on 01 Dec 2010, 01:10 PM

This sounds weak but right now it's working without having changed anything. Maybe there was something else that caused it. If I find out I'll post a follow up.

Thanks for your help!

0
Veli
Telerik team
answered on 01 Dec 2010, 01:13 PM
The GridBoundColumn does not apply any formatting to edited values. I believe this is also mentioned in the forum thread from the previous post. The reason is the potential threat of losing precision or modifying the original value without user intervention, which is unacceptable behavior for a UI component. You can use a GridDateTimeColumn and set its EditDataFormatString property to the format you need. This format will be applied to the date picker that will be initialized for editing values under this column.

Regards,
Veli
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Moe Greene
Top achievements
Rank 1
Answers by
Veli
Telerik team
Princy
Top achievements
Rank 2
Moe Greene
Top achievements
Rank 1
Share this question
or