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

GridNumericColumnEditor Currency Formatting in Edit Mode

2 Answers 327 Views
Grid
This is a migrated thread and some comments may be shown as answers.
alo
Top achievements
Rank 1
alo asked on 20 Feb 2009, 01:00 AM
I have assigned a GridNumericColumnEditor to a GridNumericColumn as follows:

<telerik:GridNumericColumn DataField="PaymentAmount" DataType="System.Decimal"   HeaderText="Payment Amount" UniqueName="PaymentAmount" DataFormatString="{0:C2}" NumericType="Currency" ColumnEditorID="GridCurrencyColumnEditor">  
</telerik:GridNumericColumn> 
 

I have defined the GridNumericColumnEditor as follows:

<telerik:GridNumericColumnEditor ID="GridCurrencyColumnEditor" runat="server">  
        <NumericTextBox Culture="English (United States)" LabelCssClass="" InvalidStyleDuration="100" 
            Type="Currency" runat="server">  
            <NumberFormat AllowRounding="True" KeepNotRoundedValue="False" DecimalDigits="2"></NumberFormat> 
        </NumericTextBox> 
</telerik:GridNumericColumnEditor> 

 

While in edit mode, the currency fields are not being displayed with two decimal places.  If I enter 1,234 I get $1,234 displayed when I am expecting to get $1,234.00.  If I enter 1,234.1234 I get $1,234.1234 displayed when I am expecting to get $1,234.12.

While in display mode, the formatting works properly based on the DataFormatString attribute in the GridNumericColumn.
 
Am I doing something wrong with the number formatting?

Al

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 20 Feb 2009, 06:04 AM
Hi,

DataFormatString is not applied for the controls generated for Edit/Insert mode. So one suggestion to achieve this is by accessing the textbox control and formating the value as shown below.

CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
{  
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
    {             
        RadNumericTextBox textBox = ((GridEditableItem)e.Item)["Freight"].Controls[0] as RadNumericTextBox;  
        textBox.NumberFormat.AllowRounding= true;  
        textBox.NumberFormat.DecimalDigits = 2;              
    }   

Thanks,
Princy.
0
alo
Top achievements
Rank 1
answered on 20 Feb 2009, 06:39 AM
Your suggestion worked great.

Thanks for the prompt response!

Al
Tags
Grid
Asked by
alo
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
alo
Top achievements
Rank 1
Share this question
or