My grid is bound to my class. One of the fields is a date which I bind to a GridDateTimeColumn.
Using in place edit when I attempt to add a new record I keep getting the error
The string was not recognized as a valid DateTime. ---> System.FormatException: The string was not recognized as a valid DateTime.
The code in my aspx page:
<telerik:GridDateTimeColumn
DataField="StartDate"
HeaderText="Start Date"
UniqueName="Start Date"
PickerType="DatePicker" />
Just checking to see if there is something I am missing. I would like the date value to default to the current date/time. Do I need to handle an event for the grid such as the edit item being created and default the editor?
Using in place edit when I attempt to add a new record I keep getting the error
The string was not recognized as a valid DateTime. ---> System.FormatException: The string was not recognized as a valid DateTime.
The code in my aspx page:
<telerik:GridDateTimeColumn
DataField="StartDate"
HeaderText="Start Date"
UniqueName="Start Date"
PickerType="DatePicker" />
Just checking to see if there is something I am missing. I would like the date value to default to the current date/time. Do I need to handle an event for the grid such as the edit item being created and default the editor?
9 Answers, 1 is accepted
0
Hello Eric,
The exception is clear that the value entered is not a recognized datetime format. Can you please provide a little bit more informaiton on the particular implementation at your end? for example- does the exception occur only with specific date entry, or at all times? Additionally, are you populating the edit form manually, or deriving and entering some default values?
Regards,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
The exception is clear that the value entered is not a recognized datetime format. Can you please provide a little bit more informaiton on the particular implementation at your end? for example- does the exception occur only with specific date entry, or at all times? Additionally, are you populating the edit form manually, or deriving and entering some default values?
Regards,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Eric Schoenholzer
Top achievements
Rank 2
answered on 22 Feb 2008, 01:38 AM
I have the same problem using this code:
| <telerik:GridDateTimeColumn UniqueName="Bezahlt" PickerType="DatePicker" HeaderText="Bezahlt" DataFormatString="{0:d}" DataField="Wann"> |
| <ItemStyle Width="120px" /> |
| </telerik:GridDateTimeColumn> |
(I'm using the German UICulture)
I think with "Prometheus" you should simplify the whole thing, without the need to construct a special template column.
0
Hi Eric,
In this case, make sure that the value coming from the database is compatible and recognizable by the control. Other than that, the template column is pretty straightforward and easy to use, and its designed purpose is to allow further customization, on a column that does not meet your requirements fully.
Best wishes,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
In this case, make sure that the value coming from the database is compatible and recognizable by the control. Other than that, the template column is pretty straightforward and easy to use, and its designed purpose is to allow further customization, on a column that does not meet your requirements fully.
Best wishes,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Eric Schoenholzer
Top achievements
Rank 2
answered on 27 Feb 2008, 11:31 PM
Hi,
The control is directly bound to a datetime SQL data field.
The date is chosen via dropdown.
In the grid, the date is shown correctly.
My 'complain' is the purpose of the GridDateTimeColumn.
How I understand, I can use the GridDateTimeColumn only if I use the english UI culture. For all others languages I need to construct it via template column.
Correct? If not, what I'm doing wrong?
Thanks
Eric
The control is directly bound to a datetime SQL data field.
The date is chosen via dropdown.
In the grid, the date is shown correctly.
My 'complain' is the purpose of the GridDateTimeColumn.
How I understand, I can use the GridDateTimeColumn only if I use the english UI culture. For all others languages I need to construct it via template column.
Correct? If not, what I'm doing wrong?
Thanks
Eric
0
Hi Eric,
If the data is coming from the database as a valid one, it should be recognized by the control. To test the case, you can bind a simple calendar control, and see if it parses it correctly. If the issue persists, you can open a formal support ticket, and send us a small working project, which demonstrates the issue, for further review.
Best wishes,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
If the data is coming from the database as a valid one, it should be recognized by the control. To test the case, you can bind a simple calendar control, and see if it parses it correctly. If the issue persists, you can open a formal support ticket, and send us a small working project, which demonstrates the issue, for further review.
Best wishes,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Daniel
Top achievements
Rank 1
answered on 14 May 2008, 08:57 PM
I'm receiving this exact same error.
This is not a binding issue, as it occurs when trying to INSERT a new record. As soon as the "Add new record" is selected, this error occurs.
This is not a binding issue, as it occurs when trying to INSERT a new record. As soon as the "Add new record" is selected, this error occurs.
0
Hello Daniel,
Can you please verify that the relevant column in the underlying data source is of type DateTime? I tried to recreate the issue in a sample project very similar to this integration example but without much success. Can it be that you are attempting to set initial date selected in the editor (wiring the ItemCommand event as shown here) and the value you pass is not valid date time?
The answers to these questions can lead us to the core of the problem to eliminate it accordingly.
Kind regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Can you please verify that the relevant column in the underlying data source is of type DateTime? I tried to recreate the issue in a sample project very similar to this integration example but without much success. Can it be that you are attempting to set initial date selected in the editor (wiring the ItemCommand event as shown here) and the value you pass is not valid date time?
The answers to these questions can lead us to the core of the problem to eliminate it accordingly.
Kind regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Daniel
Top achievements
Rank 1
answered on 20 May 2008, 02:33 PM
I've figured it out. Its an issue if the data source column name has a space in it.
Take for instance this table:
With this webpage:
This webpage, as is, will give you the error when you click on Add New Record.
If, you change the Data Source to
and change the grid's definition accordingly, there isn't a problem.
Take for instance this table:
| CREATE TABLE [dbo].[TelerikTest]( |
| [ID] [int] IDENTITY(1,1) NOT NULL, |
| [DateTime Column] [smalldatetime] NOT NULL, |
| CONSTRAINT [PK_TelerikTest] PRIMARY KEY CLUSTERED |
| ( |
| [ID] ASC |
| )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY] |
| ) ON [PRIMARY] |
With this webpage:
| <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> |
| <%@ Register assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI" tagprefix="asp" %> |
| <%@ Register assembly="Telerik.Web.UI, Version=2007.3.1314.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" namespace="Telerik.Web.UI" tagprefix="telerik" %> |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head runat="server"> |
| <title>Untitled Page</title> |
| </head> |
| <body> |
| <form id="form1" runat="server"> |
| <div> |
| <asp:SqlDataSource ID="SqlDataSource1" runat="server" |
| ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" |
| SelectCommand="SELECT [ID], [DateTime Column] FROM [TelerikTest]"> |
| </asp:SqlDataSource> |
| </div> |
| <asp:ScriptManager ID="ScriptManager1" runat="server"> |
| </asp:ScriptManager> |
| <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" |
| DataSourceID="SqlDataSource1" GridLines="None"> |
| <ExportSettings> |
| <Pdf PaperSize="Letter" FontType="Subset"></Pdf> |
| <Excel Format="Html"></Excel> |
| </ExportSettings> |
| <MasterTableView CurrentResetPageIndexAction="SetPageIndexToFirst" Dir="LTR" |
| Frame="Border" TableLayout="Auto" CommandItemDisplay="Top" datakeynames="ID" |
| datasourceid="SqlDataSource1"> |
| <RowIndicatorColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" Visible="False"> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" Visible="False" Resizable="False"> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </ExpandCollapseColumn> |
| <Columns> |
| <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="ID" |
| DataType="System.Int32" FilterListOptions="VaryByDataType" |
| ForceExtractValue="None" HeaderText="ID" ReadOnly="True" SortExpression="ID" |
| UniqueName="ID"> |
| </telerik:GridBoundColumn> |
| <telerik:GridDateTimeColumn DataField="[DateTime Column]" PickerType="TimePicker" |
| UniqueName="TimeIn" HeaderText="Time In" > |
| </telerik:GridDateTimeColumn> |
| </Columns> |
| <EditFormSettings> |
| <EditColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType"></EditColumn> |
| </EditFormSettings> |
| </MasterTableView> |
| </telerik:RadGrid> |
| </form> |
| </body> |
| </html> |
This webpage, as is, will give you the error when you click on Add New Record.
If, you change the Data Source to
| <asp:SqlDataSource ID="SqlDataSource1" runat="server" |
| ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" |
| SelectCommand="SELECT [ID], [DateTime Column] as DateTime_Column FROM [TelerikTest]"> |
| </asp:SqlDataSource> |
and change the grid's definition accordingly, there isn't a problem.
0
Hello Daniel,
Indeed space is not allowed as part of the column name when you assign it through the DataField property of the respective RadGrid column. Feel free to use the workaround you already discovered to avoid the unexpected results.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Indeed space is not allowed as part of the column name when you assign it through the DataField property of the respective RadGrid column. Feel free to use the workaround you already discovered to avoid the unexpected results.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center