无法将参数'Date'的值转换为'System.DateTime'类型。

时间:2015-05-13 10:20:17

标签: c# asp.net entity-framework entity-framework-6 radgrid

我使用EntityDataSource,我在格式化日期后得到错误转换

像那样:DataFormatString="{0:dd/MM/yyyy}"

[EntityDataSourceValidationException: Error while setting property 'fromDate': 'Cannot convert the value of parameter 'fromDate' to the type 'System.DateTime'.'.]
   Microsoft.AspNet.EntityDataSource.EntityDataSourceView.ConvertProperties(IDictionary values, PropertyDescriptorCollection propertyDescriptors, ParameterCollection referenceParameters, Dictionary`2 convertedValues) +737
   Microsoft.AspNet.EntityDataSource.EntityDataSourceView.ExecuteDelete(IDictionary keys, IDictionary oldValues) +383
   System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) +84
   Telerik.Web.UI.GridTableView.PerformDelete(GridEditableItem editedItem, Boolean suppressRebind) +228
   Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +2417
   Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +91
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37

我的aspx:

 <telerik:GridDateTimeColumn HeaderText="تاريخ البداية" UniqueName="fromDate" SortExpression="fromDate" DataField="fromDate" DataFormatString="{0:dd/MM/yyyy}"></telerik:GridDateTimeColumn>
  

注意:sqlserver db中的fromDate类型为Date

1 个答案:

答案 0 :(得分:1)

试试:

<telerik:GridBoundColumn DataField="fromDate" DataType="System.DateTime" HeaderText="تاريخ البداية"     
  UniqueName="fromDate" DataFormatString="{0:dd/MM/yyyy}" HtmlEncode="false"/>