Last post Jan 12, 2011 07:24 PM by sjnaughton
Jan 11, 2011 01:42 PM|mbowles|LINK
Have a textbox in edit mode of a formview (using linq) and need to show the value of an int in a text box with a $ and , (comma) for thousands, etc...
On update it needs to send just the raw number, so $12,250 would send 12250 to the database. Can this be done in custom metadata, and I don't mind writing a custom field template?
Jan 11, 2011 02:37 PM|Shuvo Aymon|LINK
You may user decimal.TryParse() to get numeric value from currency
string s = "$123,456.78";
bool ok = decimal.TryParse(s, NumberStyles.Currency,CultureInfo.CurrentCulture.NumberFormat, out value);
if (ok) then you will find 123456.78 in value.
Jan 11, 2011 03:23 PM|mbowles|LINK
I see what you are saying (it is an integer for this app, whole dollars) but how do I do that for an update that comes from a dynamically created FormView via dynamicdata? Intercept button click, loop though form fields, etc?
Jan 12, 2011 07:24 PM|sjnaughton|LINK
Hi Mbowles, you use the DataType to set the format you want, but to get it to show in edit mode is a little more tricky. The main reason is that when the value is saved that format will then be saved with it. To get it to show in Edit mode in a custom field
template instead of using FieldValueEditString you would use the FieldValueString which retains the format. However in the Extract values method you will need to do some cleanup of the value before saving it to the dictionary.
Dynamic Data 4