Hi,
When I click the delete button on my RadGrid, I get this error:
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Stack Trace:
Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927
I found that this data format string is the culprit:
<telerik:GridBoundColumn DataField="Price" DataFormatString="{0:c}" DataType="System.Decimal"
HeaderText="Price" SortExpression="Price" UniqueName="Price">
</telerik:GridBoundColumn>
Here is all of my code:
This also happens with the Numeric Column type. What can I do to resolve this error without removing the data format string?
When I click the delete button on my RadGrid, I get this error:
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
|
Stack Trace:
[FormatException: Input string was not in a correct format.] System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +10161267 System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt) +238 System.String.System.IConvertible.ToDecimal(IFormatProvider provider) +88 System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) +750 System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) +156 System.Web.UI.WebControls.Parameter.GetValue(Object value, Boolean ignoreNullableTypeChanges) +298 System.Web.UI.WebControls.SqlDataSourceView.AddParameters(DbCommand command, ParameterCollection reference, IDictionary parameters, IDictionary exclusionList, String oldValuesParameterFormatString) +808 System.Web.UI.WebControls.SqlDataSourceView.ExecuteDelete(IDictionary keys, IDictionary oldValues) +343 System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) +4052080 Telerik.Web.UI.GridTableView.PerformDelete(GridEditableItem editedItem, Boolean suppressRebind) +268 Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +2406 Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +185 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70 Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +142 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981 |
Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927
I found that this data format string is the culprit:
<telerik:GridBoundColumn DataField="Price" DataFormatString="{0:c}" DataType="System.Decimal"
HeaderText="Price" SortExpression="Price" UniqueName="Price">
</telerik:GridBoundColumn>
Here is all of my code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ProductCart.ascx.cs" Inherits="UserControls_Products_ProductCart" %> |
<%--<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default"></telerik:RadAjaxLoadingPanel> |
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">--%> |
<%--</telerik:RadAjaxPanel> |
--%> |
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" |
AllowAutomaticInserts="True" AllowAutomaticUpdates="True" |
AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True" |
DataSourceID="SqlDataSource1" GridLines="None"> |
<MasterTableView AutoGenerateColumns="False" DataKeyNames="CartID,ProductID" |
DataSourceID="SqlDataSource1"> |
<RowIndicatorColumn> |
<HeaderStyle Width="20px"></HeaderStyle> |
</RowIndicatorColumn> |
<ExpandCollapseColumn> |
<HeaderStyle Width="20px"></HeaderStyle> |
</ExpandCollapseColumn> |
<Columns> |
<telerik:GridBoundColumn DataField="CartID" HeaderText="CartID" ReadOnly="True" |
SortExpression="CartID" UniqueName="CartID" Visible="false"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="ProductID" HeaderText="ProductID" |
ReadOnly="True" SortExpression="ProductID" UniqueName="ProductID" Visible="false"> </telerik:GridBoundColumn> |
<telerik:GridDropDownColumn DataField="ProductID" |
DataSourceID="ObjectDataSource1" HeaderText="Product" |
ListTextField="Name" ListValueField="ID" UniqueName="procolumn1"> |
</telerik:GridDropDownColumn> |
<telerik:GridBoundColumn DataField="Price" DataFormatString="{0:c}" DataType="System.Decimal" |
HeaderText="Price" SortExpression="Price" UniqueName="Price"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="Quantity" DataType="System.Int32" |
HeaderText="Quantity" SortExpression="Quantity" UniqueName="Quantity"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="TimeStamp" DataType="System.DateTime" |
HeaderText="TimeStamp" SortExpression="TimeStamp" UniqueName="TimeStamp"> |
</telerik:GridBoundColumn> |
</Columns> |
</MasterTableView> |
</telerik:RadGrid> |
<asp:SqlDataSource ID="SqlDataSource1" runat="server" |
ConflictDetection="CompareAllValues" |
ConnectionString="<%$ ConnectionStrings:WilliamsFireConnectionString %>" |
DeleteCommand="DELETE FROM [product_cart] WHERE [CartID] = @original_CartID AND [ProductID] = @original_ProductID AND [Price] = @original_Price AND [Quantity] = @original_Quantity AND [TimeStamp] = @original_TimeStamp" |
InsertCommand="INSERT INTO [product_cart] ([CartID], [ProductID], [Price], [Quantity], [TimeStamp]) VALUES (@CartID, @ProductID, @Price, @Quantity, @TimeStamp)" |
OldValuesParameterFormatString="original_{0}" |
SelectCommand="SELECT * FROM [product_cart] WHERE ([CartID] = @CartID)" |
UpdateCommand="UPDATE [product_cart] SET [Price] = @Price, [Quantity] = @Quantity, [TimeStamp] = @TimeStamp WHERE [CartID] = @original_CartID AND [ProductID] = @original_ProductID AND [Price] = @original_Price AND [Quantity] = @original_Quantity AND [TimeStamp] = @original_TimeStamp"> |
<DeleteParameters> |
<asp:Parameter Name="original_CartID" Type="String" /> |
<asp:Parameter Name="original_ProductID" Type="String" /> |
<asp:Parameter Name="original_Price" Type="Decimal" /> |
<asp:Parameter Name="original_Quantity" Type="Int32" /> |
<asp:Parameter Name="original_TimeStamp" Type="DateTime" /> |
</DeleteParameters> |
<InsertParameters> |
<asp:Parameter Name="CartID" Type="String" /> |
<asp:Parameter Name="ProductID" Type="String" /> |
<asp:Parameter Name="Price" Type="Decimal" /> |
<asp:Parameter Name="Quantity" Type="Int32" /> |
<asp:Parameter Name="TimeStamp" Type="DateTime" /> |
</InsertParameters> |
<SelectParameters> |
<asp:SessionParameter Name="CartID" SessionField="WilliamsFireShop_CartID" |
Type="String" /> |
</SelectParameters> |
<UpdateParameters> |
<asp:Parameter Name="Price" Type="Decimal" /> |
<asp:Parameter Name="Quantity" Type="Int32" /> |
<asp:Parameter Name="TimeStamp" Type="DateTime" /> |
<asp:Parameter Name="original_CartID" Type="String" /> |
<asp:Parameter Name="original_ProductID" Type="String" /> |
<asp:Parameter Name="original_Price" Type="Decimal" /> |
<asp:Parameter Name="original_Quantity" Type="Int32" /> |
<asp:Parameter Name="original_TimeStamp" Type="DateTime" /> |
</UpdateParameters> |
</asp:SqlDataSource> |
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" |
SelectMethod="GetAllProducts" TypeName="WilliamsProducts.WilliamsProducts"> |
</asp:ObjectDataSource> |
This also happens with the Numeric Column type. What can I do to resolve this error without removing the data format string?