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

DateTime data in RadGrid

5 Answers 626 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Harri
Top achievements
Rank 1
Harri asked on 11 Apr 2016, 12:56 PM

Hi

We have "datarow" in class and "dataset" is from ObservableCollection. There are normal set and get for public properties. We use ObjectDataSource to get "dataset" and there are also insert, update and delete commands. All other things seems to work but we have problems with DateTime type properties. Those are tested in GridBoundColumn and GridDateTimeColumn and always same problem. Those are shown correctly with user date format or given datastringformat but when updating or inserting it always crash before our own codes to conversion from "System.String" to "System.DateTime". Only way we have got it work properly is use ISO standard type format "yyyy-MM-dd HH:mm:ss" when setting the value which is not acceptable way to work. So how these datetimes should be set to columns that those are shown and editable in user format and not crash somewhere before it even get to our own code?

5 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 14 Apr 2016, 11:30 AM
Hello,

Note that when you are using DateTime column or a Bound column with DateTime set the System.DateTime you should pass DateTime type of fields form the DB to those columns. Otherwise you should perform manual conversion of the data before inserting it into the DB.

Regards,
Maria Ilieva
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Harri
Top achievements
Rank 1
answered on 14 Apr 2016, 12:30 PM

Hi

We are using DateTime from db (Oracle db field named EnrollmentDate type Date) to class properte (Enrollment class with property EnrollmentDate) to observablecollection with that class (ObservableCollection<Enrollment>) and to asp elements.

Below are two asp parts (Bound or DateTime) which has been tested:

<telerik:GridBoundColumn DataField="EnrollmentDate" HeaderText="EnrollmentDate" SortExpression="EnrollmentDate" UniqueName="EnrollmentDate" DataType="System.DateTime" FilterControlAltText="Filter EnrollmentDate column"></telerik:GridBoundColumn>
 
<telerik:GridDateTimeColumn DataField="EnrollmentDate" HeaderText="EnrollmentDate" SortExpression="EnrollmentDate" UniqueName="EnrollmentDate" DataType="System.DateTime" FilterControlAltText="Filter EnrollmentDate column"></telerik:GridDateTimeColumn>

 

In Class "Enrollment" that property "EnrollmentDate" is defined as follows:

public DateTime? EnrollmentDate
{
    get
    {
        return _EnrollmentDate;
    }
    set
    {
        _EnrollmentDate = value;
        OnPropertyChanged("EnrollmentDate");
    }
}

 

Setting data to that class property from DB:

objEnrollments.EnrollmentDate = dr.Field<DateTime?>("EnrollmentDate");

 

So where is the problem point?

 

If there is no problem, where is your mentioned before inserting, because it crash just after clicking update/insert button and not go in any event (or I haven't find right one).

 

BR

Harri

0
Maria Ilieva
Telerik team
answered on 19 Apr 2016, 02:35 PM
Hi,

Can you please send us the full error stack trace so that we can revise it locally and investigate further for its root cause?

Regards,
Maria Ilieva
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Harri
Top achievements
Rank 1
answered on 12 Sep 2016, 06:02 AM

Hi,

Sorry for long reply, some other projects :) Co worker found that there is solution for this. That was adding ParsingCulture="Current" to ObjectDataSource which we used for grid. So there is no more problems with datetime (or decimal numbers).

 

Regards,

Harri

0
Maria Ilieva
Telerik team
answered on 14 Sep 2016, 02:47 PM
Hello Harri,

Thank you for getting back to us and for the provided update on this case. Do not hesitate to contact us back in case further assistance is needed.

Regards,
Maria Ilieva
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Harri
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Harri
Top achievements
Rank 1
Share this question
or