I an ObjectDataSource to databind a ListView to a collection of CashItems retrieved from a CashDatabinder class and to update them:
[DataObject]
public class CashDatabinder
{
[DataObjectMethod(DataObjectMethodType.Select)]
public List<cashitem> GetItems()
{...}
[DataObjectMethod(DataObjectMethodType.Update)]
public void UpdateItem(CashItem item)
{...}
}
</cashitem>
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.