This is a migrated thread and some comments may be shown as answers.

Format string in template and bind

2 Answers 219 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Felice
Top achievements
Rank 1
Felice asked on 28 Mar 2014, 02:28 PM
I have this line of code in a radGrid template:
<asp:TextBox ID="TextBox12" runat="server" Text='<%# Bind( "valuePCS" ) %>'></asp:TextBox>
and it is working fine.

My problem is that I would like to show the format "€" but if I add the formatting like this:
<asp:TextBox ID="TextBox12" runat="server" Text='<%# Bind( "valuePCS", "{0:C0}" ) %>'></asp:TextBox>

on the first insert of the new record the formatting is not shown yet then the record is saved without problems;
if I open again the record, this time the formatting is visible and if I update the record it gives an error on the input string formatting.

Error:
[FormatException: Formato della stringa di input non corretto.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +10896279
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +145
   System.String.System.IConvertible.ToInt32(IFormatProvider provider) +46
   System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) +297
   System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) +126
   System.Web.UI.WebControls.Parameter.GetValue(Object value, Boolean ignoreNullableTypeChanges) +63
   System.Web.UI.WebControls.SqlDataSourceView.AddParameters(DbCommand command, ParameterCollection reference, IDictionary parameters, IDictionary exclusionList, String oldValuesParameterFormatString) +535
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +324
   System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +87
   Telerik.Web.UI.GridTableView.PerformUpdate(GridEditableItem editedItem, Boolean suppressRebind) +430
   Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +2063
   Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +205
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   Telerik.Web.UI.GridEditFormItem.OnBubbleEvent(Object source, EventArgs e) +372
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +114
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +252
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

How do I solve this problem?
Thanks,
Felice

2 Answers, 1 is accepted

Sort by
0
Accepted
Vasil
Telerik team
answered on 28 Mar 2014, 02:47 PM
Hi Felice,

Use RadNumericTextBox and bind the valuePCS to the DbValue property of the control. Then you will be able to set any format you desire.
This will allow you to have one  format string value that you show to the client, and another floating type variable that will be send  to the data provider on updating.

Regards,
Vasil
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
Felice
Top achievements
Rank 1
answered on 28 Mar 2014, 04:26 PM
Grate! You solved my problem. It is working perfectly.
Thank you Vasil
Tags
Grid
Asked by
Felice
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Felice
Top achievements
Rank 1
Share this question
or