Click here to Skip to main content
15,612,595 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I an ObjectDataSource to databind a ListView to a collection of CashItems retrieved from a CashDatabinder class and to update them:
public class CashDatabinder
public List<cashitem> GetItems()

public void UpdateItem(CashItem item)

My CashItems have an "Amount" double property which is one of the properties that can be updated via the ListView.

Therefore, in the EditItemTemplate I have something like
<asp:TextBox ID="TextBoxAmount" runat="server" Text='<%# Bind("Amount") %>' />

As the end users want the app in french, they want to enter the amount using the "," as decimal separator.

The problem is that when updating with an amount with decimals, I get

[FormatException: Input string was not in a correct format.]
   System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt) +454
   System.ComponentModel.DoubleConverter.FromString(String value, NumberFormatInfo formatInfo) +46
   System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) +497

[Exception: 729,5 is not a valid value for Double.]
   System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) +8019613
   System.Web.UI.WebControls.ObjectDataSourceView.ConvertType(Object value, Type type, String paramName) +130
   System.Web.UI.WebControls.ObjectDataSourceView.BuildObjectValue(Object value, Type destinationType, String paramName) +222
   System.Web.UI.WebControls.ObjectDataSourceView.BuildDataObject(Type dataObjectType, IDictionary inputParameters) +595
   System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +912
   System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +3696709
   System.Web.UI.WebControls.ListView.HandleUpdate(ListViewItem item, Int32 itemIndex, Boolean causesValidation) +1350
   System.Web.UI.WebControls.ListView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +636
   System.Web.UI.WebControls.ListViewDataItem.OnBubbleEvent(Object source, EventArgs e) +164
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +52
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707

I could find a workaround by implementing the ItemUpdating event of the ListView in order to manually convert the amount from a string to a double but I was wondering if there wasn't an easier way to do that, for example in the markups, as I might have later more properties that would generate the same problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900