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

Issues w/ Radgrid Maskedcolumn Input

2 Answers 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vin
Top achievements
Rank 1
Vin asked on 17 Nov 2010, 03:18 PM
Have a grid w/ in-place editing enabled. One of the fields stores a dollar amount (unit price) which is databound to my sql database via an sqldatasource, decimal(10,2) field. The column definition is as follows:

 

<telerik:GridMaskedColumn DataField="UnitPrice" DisplayMask="" 
HeaderText="Unit Price" Mask="$##,###.##" UniqueName="Unit Price" 
DataFormatString="{0:C2}"
<HeaderStyle HorizontalAlign="Center" Width="100px" /> 
<ItemStyle HorizontalAlign="Center" Width="100px" /> 
</telerik:GridMaskedColumn>

 

 

 


Let's take an item with a unit price of $110.00 from the database.

When the grid initially loads, the column properly displays the amount as $110.00

If I click edit, my in-place editing form appears and the input box for the unit price appears as:

$11,0__.00

Suffice to say, this is clearly incorrect. There are other editable columns in the grid... if the user intends to edit a different field (such as description) they also have to "correct" the incorrect unit price -- each and every time they perform an edit operation -- otherwise if they attempt to update w/o correcting it, they receive a "Exception Details: System.FormatException: Input string was not in a correct format." error when trying to update. This is very annoying to the user community.

Why is the masked control displaying the data incorrectly for edit, and how can I correct it so the value is properly displayed on the edit form to avoid this issue?

2 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 23 Nov 2010, 09:45 AM
Hello Vin,

I recommend that you a GridNumericColumn to implement the desired functionality:
ASPX
<telerik:GridNumericColumn DataField="UnitPrice" HeaderText="Unit Price" UniqueName="UnitPrice"
    DataFormatString="{0:C2}">
    <HeaderStyle HorizontalAlign="Center" Width="100px" />
</telerik:GridNumericColumn>
Code behind
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
    {
        RadNumericTextBox numBox = (e.Item as GridEditFormItem)["UnitPrice"].Controls[0] as RadNumericTextBox;
        numBox.Type = NumericType.Currency;
        numBox.NumberFormat.DecimalDigits = 2;
        numBox.NumberFormat.DecimalSeparator = ".";
        numBox.NumberFormat.GroupSeparator = ",";
        numBox.NumberFormat.GroupSizes = 3;
        numBox.NumberFormat.KeepTrailingZerosOnFocus = true;
    }
}

I hope this helps.

Sincerely yours,
Mira
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Vin
Top achievements
Rank 1
answered on 23 Nov 2010, 08:50 PM
Thanks. I finally figured that out yesterday, I'm used to using C# .NET controls so naturally thought the Masked control would be the proper one to use, but finally came across the currency setting in the numeric control.
Tags
Grid
Asked by
Vin
Top achievements
Rank 1
Answers by
Mira
Telerik team
Vin
Top achievements
Rank 1
Share this question
or