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

DataFormatString="{0:M/d/yyyy}" doesn't work

9 Answers 1889 Views
Grid
This is a migrated thread and some comments may be shown as answers.
pentru
Top achievements
Rank 1
pentru asked on 18 Feb 2009, 04:29 PM
Hi !

I have a grid where I have to set one a column DateTime in ShortDate format (2/18/2009).The fetches data in DataField="MyDate" is in the format with time ( 2/4/2009 7:25:21 PM)
To display only datatime without time I'm using :

<telerik:GridBoundColumn
DataField="MyDate"
HeaderText="Date"
UniqueName="MyDate"

 

DataFormatString="{0:M/d/yyyy}"

 

HtmlEncode="false">

 

</telerik:GridBoundColumn>

 

 

.......
but no efect, the data displayed is in the same format with time.

Please help to solve the problem , I need to display datatime without time !!!!!!!
Thanks.

9 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 19 Feb 2009, 07:30 AM
Hi Pentru,

I tried setting the DataFormatString for the column as you did and it is working as expected(showing only date and not time). Can you try with a GridDateTimeColumn instead of a GridBoundColumn and see whether it is working.

ASPX:
  
  <telerik:GridDateTimeColumn DataField="MyDate" UniqueName="MyDate" DataFormatString="{0:M/d/yyyy}" HeaderText="Date" ></telerik:GridDateTimeColumn> 

Thanks
Shinu

0
pentru
Top achievements
Rank 1
answered on 22 Feb 2009, 06:40 PM
Hi Shinu!

Thank you very much for your response, but still I have the same issues.

I used property GridDateTimeColumn instead of a GridBoundColumn but no effect.

It very strange because with the same datasource on asp:GridView this format (DataFormatString="{0:M/d/yyyy}" or ="{0:d}") is working !!!!!!!
It’s something wrong with telerik:RadGrid but I don’t know what, I can not remove time from date.

So fare I used:

1).  
 
    <telerik:GridTemplateColumn DataField=" MyDate " HeaderText="Date" UniqueName="MyDate" DataType="System.DateTime">   
         <ItemTemplate>   
            <asp:Label ID=" MyDateLabel" runat="server" Text='<%# Eval("MyDate", "{0:M/d/yyyy}") %>'></asp:Label>   
         </ItemTemplate>   
         <EditItemTemplate>   
            <asp:TextBox ID=" MyDateTextBox" runat="server" Text='<%# Bind("MyDate","{0:M/d/yyyy}") %>'></asp:TextBox>   
         </EditItemTemplate>                               
 
     </telerik:GridTemplateColumn>   
   
 
2).                              
 
<telerik:GridDateTimeColumn DataField="MyDate" UniqueName="MyDate"   
 
DataFormatString="{0:M/d/yyyy}" 
 
 HeaderText="Date" > 
 
</telerik:GridDateTimeColumn> 
 
 
 
3)

<telerik:GridBoundColumn
DataField="MyDate"
HeaderText="Date"
UniqueName="MyDate"

 

DataFormatString="{0:M/d/yyyy}"

HtmlEncode="false">

 

</telerik:GridBoundColumn>

 

but not effect, I mean the date is displayed with time like this:  2/4/2009 7:23:55 PM.

 

I’m going to be crazy with this telerik grid.

 

If you have any idea how to dislay date without time, please help !!!!!!

 

Thank you very much.

 

 

 

 

 

 

0
Shinu
Top achievements
Rank 1
answered on 23 Feb 2009, 05:32 AM
Hi Pentru,

Which version of the Grid are you using? Mine is RadControls for AJAX version(2008.3.1314.20). If you are using an older version consider upgrading to the latest version of the Grid.  You can also give a try with the Trial version of the Grid available here.

Shinu
0
Accepted
Daniel
Telerik team
answered on 23 Feb 2009, 06:25 AM
Hello Pentru,

I modified your code-snippet:
<telerik:GridBoundColumn DataField="MyDate" DataType="System.DateTime" HeaderText="Date" 
  UniqueName="MyDate" DataFormatString="{0:M/d/yyyy}" HtmlEncode="false"/

Note that the data type (in the DB) should be DateTime.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
pentru
Top achievements
Rank 1
answered on 24 Feb 2009, 10:37 PM
Hi Daniel and Shinu !

Thank you very much. I managed to solved the issue, now is working.
I used your code:
<telerik:GridBoundColumn DataField="MyDate" DataType="System.DateTime" HeaderText="Date"    
  UniqueName="MyDate" DataFormatString="{0:M/d/yyyy}" HtmlEncode="false"/> 

Thanks again.
0
Myriam
Top achievements
Rank 1
answered on 12 Aug 2009, 06:34 PM
I have the same problem but unfortunatly your solution doesn't work for me.
Here is my code:
<telerik:GridBoundColumn   
                                    SortExpression="DATE_SOUMISSION"   
                                    HeaderText="Date soumission demande"   
                                    DataField="DATE_SOUMISSION"   
                                    UniqueName="DATE_SOUMISSION" 
                                    DataType="System.DateTime" 
                                    ReadOnly=true htmlEncode="False"  DataFormatString={0:dd/MM/yyyy}> 
                                </telerik:GridBoundColumn> 
And my field is a datetime type in my db
Message d'erreur de l'analyseur: Le contenu littéral ('<telerik:GridBoundColumn
                                   SortExpression="DATE_SOUMISSION"
                                   HeaderText="Date soumission demande"
                                   DataField="DATE_SOUMISSION"
                                   UniqueName="DATE_SOUMISSION"
                                   DataType="System.DateTime"
                                   ReadOnly=true htmlEncode="False"  DataFormatString={0:dd/MM/yyyy}>
                               </telerik:GridBoundColumn>') n'est pas autorisé dans un 'Telerik.Web.UI.GridColumnCollection'.
Which means that GridBoundColumn etc.. is not autorised in a 'Telerik.Web.UI.GridColumnCollection'.
Any Idea?
Maybe it could help to know that my HtmlEncode is underline in green and says that it is not a validated attribute of GridBoundColumn...
Thank you
0
Myriam
Top achievements
Rank 1
answered on 12 Aug 2009, 06:52 PM
Forget that!
I forgot the double quote around the dataformatstring value!
Thanks anyway
0
Big_G
Top achievements
Rank 1
answered on 14 Sep 2010, 04:39 PM
I have the following code but getting an error: Type 'System.DateTime' was not found.

I tried adding the namespace in my xaml for mscorlib but no luck.


 

 

 

<tlk:GridViewDataColumn DataMemberBinding="{Binding TradeDate}" DataType="System.DateTime"

 

 

 

Width="70" DataFormatString="{}{0:M/dd/yyyy}"

 

 

 

UniqueName="TradeDate" >

 

 

 

 

<tlk:GridViewDataColumn.Header>

 

 

 

 

<TextBlock Text="Trade Date" TextWrapping="Wrap" />

 

 

 

 

</tlk:GridViewDataColumn.Header>

 

 

 

 

</tlk:GridViewDataColumn>

 

0
Daniel
Telerik team
answered on 14 Sep 2010, 09:53 PM
Hello Giancarlo,

I suppose this is a Silverlight-related question. If this is so, can you please re-post this in our Silverlight forums?

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
pentru
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
pentru
Top achievements
Rank 1
Daniel
Telerik team
Myriam
Top achievements
Rank 1
Big_G
Top achievements
Rank 1
Share this question
or