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

String was not recognized as a valid DateTime.

3 Answers 661 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joshy Varghese
Top achievements
Rank 1
Joshy Varghese asked on 21 Oct 2011, 02:58 PM
Hi,
I'm using latest version Q2 2011 telerik controls. I'm getting an exception on grid  ItemDataBound event only on edit command. Initial databound and paging, sorting are good.

In my database both fields are datetime.

StartTime                                    EndTime                                            
2011-09-30 00:00:00.000            2011-09-30 15:34:33.203

In the radGrid
Start Time                                     End Time
9/30/2011 12:00:00 AM                9/30/2011 3:34:33 PM

EditMode

="InPlace"

OnNeedDataSource="grdTime_NeedDataSource" (binding the data on server side using EntityFramework)
<Columns>

 <telerik:GridDateTimeColumn DataField="StartTime" HeaderButtonType="TextButton" HeaderText="Start Time" ItemStyle-HorizontalAlign="Left" UniqueName="StartTime" ItemStyle-Width="100px" HeaderStyle-Width="100px" ReadOnly="true" DataType="System.DateTime">

 </telerik:GridDateTimeColumn>

 <telerik:GridDateTimeColumn DataField="EndTime" HeaderButtonType="TextButton" HeaderText="End Time" ItemStyle-HorizontalAlign="Left" UniqueName="EndTime" ItemStyle-Width="100px" HeaderStyle-Width="100px" PickerType="DateTimePicker" DataType="System.DateTime">

 </telerik:GridDateTimeColumn>

</Columns>

Getting the "String was not recognized as a valid DateTime." exception on hitting edit button.

Thanks!

 

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Oct 2011, 03:14 PM
Hello Joshy,

I have tried to recreate the issue at my end but no avail. Please make sure that the value coming from the database is compatible and recognizable by the control. Another suggestion is to go for a template column with DatePicker in EditItemTemplate.

Thanks,
Shinu.
0
Gabriel
Top achievements
Rank 1
answered on 01 Nov 2016, 05:09 PM

Hi there.

I have a similar scenario. I'm getting the same error when I hit the edit button only.

Either the ItemDataBound event is working good and the grid is filtering good with EnableRangeFiltering="true".

I'm sending the data from a storeprocedure as (the default database's languaje is english):

CONVERT(DATETIME ,[dScheduled] ,103) [dScheduled]

I already tried many conbinations in the EditDataFormatString property as "yyyy-MM-dd", "dd/MM/yyyy" and the like.

My code is this:

<telerik:GridDateTimeColumn DataField="dScheduled" SortExpression="dScheduled" UniqueName="dScheduled" DataType="System.DateTime" FilterControlWidth="100px" HtmlEncode="False" PickerType="DatePicker" CurrentFilterFunction="Between" AndCurrentFilterFunction="Between" ShowFilterIcon="False" EnableRangeFiltering="true" DataFormatString="{0:dd/MM/yyyy}" EditDataFormatString="yyyy-MM-dd" FilterDateFormat="dd/MM/yyyy" AutoPostBackOnFilter="True">
</telerik:GridDateTimeColumn>

 

I add the Stack Trace, just in case:

[FormatException: The string was not recognized as a valid DateTime.]
   Telerik.Web.UI.RadDatePicker.set_DbSelectedDate(Object value) +805
   Telerik.Web.UI.GridDateTimeColumnEditor.set_Text(String value) +43
   Telerik.Web.UI.GridBoundColumn.OnDataBindColumn(Object sender, EventArgs e) +1084
   System.Web.UI.Control.OnDataBinding(EventArgs e) +84
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +150
   System.Web.UI.Control.DataBind() +17
   System.Web.UI.Control.DataBindChildren() +185
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +160
   System.Web.UI.Control.DataBind() +17
   System.Web.UI.Control.DataBindChildren() +185
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +160
   System.Web.UI.Control.DataBind() +17
   System.Web.UI.Control.DataBindChildren() +185
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +160
   System.Web.UI.Control.DataBind() +17
   System.Web.UI.Control.DataBindChildren() +185
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +160
   System.Web.UI.Control.DataBind() +17
   System.Web.UI.Control.DataBindChildren() +185
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +160
   System.Web.UI.Control.DataBind() +17
   System.Web.UI.Control.DataBindChildren() +185
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +160
   System.Web.UI.Control.DataBind() +17
   System.Web.UI.Control.DataBindChildren() +185
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +160
   System.Web.UI.Control.DataBind() +17
   System.Web.UI.Control.DataBindChildren() +185
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +160
   System.Web.UI.Control.DataBind() +17
   Telerik.Web.UI.GridEditFormItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows) +224
   Telerik.Web.UI.GridItemBuilder.CreateItems(GridGroupingContext group) +953
   Telerik.Web.UI.GridTableView.CreateItems(IEnumerator enumerator, GridColumn[] columns, ControlCollection controls) +129
   Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +1852
   Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +820
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +67
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +128
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +34
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
   Telerik.Web.UI.GridTableView.PerformSelect() +16
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   Telerik.Web.UI.GridTableView.DataBind() +274
   Telerik.Web.UI.GridTableView.Rebind() +123
   Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +143
   Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +91
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +38
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +87
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +121
   System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +180
   System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639

 

Thanks.

0
Marin
Telerik team
answered on 04 Nov 2016, 08:41 AM
Hi,

The EditDataFormatString should match the format of the data coming from the database and the culture on the current page in the application, in order for the string to be parsed correctly. Verify that these formats match and then set this format to the EditDataFormatString to resolve the problem.

I hope this helps. Let me know if you have any other questions.

Regards,
Marin
Telerik by Progress
Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Tags
Grid
Asked by
Joshy Varghese
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Gabriel
Top achievements
Rank 1
Marin
Telerik team
Share this question
or