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

Edit problem for datetime column in dd/MM/YYYY formate

1 Answer 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dheeraj
Top achievements
Rank 1
Dheeraj asked on 14 Jun 2010, 04:13 PM
Hi,
      in my grid I have column defined as datetime for that i am applying DataFormatString="{0:dd/MM/yyyy}" to show it in dd/MM/YYY formate instead of default MM/dd/YYYYY formate. Now on edit of row i am getting client side scipt error like-

" The string was not recognized as a valid DateTime."

I am using <telerik:GridEditCommandColumn>  for inline editing.

How to avod this error plz help me regarding this.

Regards,
Dheeraj

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 18 Jun 2010, 07:04 AM
Hello Dheeraj,

Could you please verify whether you bind your column to a valid DateTime object? I have tested the code snippets bellow and they run as expected on my side:

Markup:

<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
    AutoGenerateColumns="false">
    <MasterTableView EditMode="InPlace">
        <Columns>
            <telerik:GridDateTimeColumn DataField="MyDateTimeField1" DataFormatString="{0:dd/MM/yyyy}" HeaderText="MyDateTimeColumn" UniqueName="MyDateTimeColumn">
            </telerik:GridDateTimeColumn>
            <telerik:GridBoundColumn DataField="MyDateTimeField2" DataFormatString="{0:dd/MM/yyyy}" HeaderText="MyBoundColumn" UniqueName="MyBoundColumn">
            </telerik:GridBoundColumn>
            <telerik:GridEditCommandColumn>
            </telerik:GridEditCommandColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

Code behind:

protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("MyDateTimeField1", typeof(DateTime));
    table.Columns.Add("MyDateTimeField2", typeof(DateTime));
    for (int i = 0; i < 10; i++)
    {
        table.Rows.Add(DateTime.Now.AddDays(i),DateTime.Now.AddDays(-i));
    }
    RadGrid1.DataSource = table;
}


I hope this helps,
Martin
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
Dheeraj
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or