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

[Solved] Data format in Edit mode

2 Answers 147 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christopher Borys
Top achievements
Rank 1
Christopher Borys asked on 09 Nov 2009, 03:01 AM
My DataForamtString is {0:#,##0;(#,##0);0} and my data value is (Decimal)0.  In a view mode, it is displayed as "0" as I want but in edit mode (in place) it turns into "0.0000".  Why? How can I control this format without explicit loading the control item?



Thanks,
Chris

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 Nov 2009, 01:38 PM
Hi Chris,

One suggestion will be accessing the control in code behind and setting the decimal digits value there.

aspx:
 
    <telerik:GridNumericColumn UniqueName="Number"  
        HeaderText="Number" DataField="Number" MaxLength="8" DataType="System.Double"
    </telerik:GridNumericColumn> 

cs:
 
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem editItem = (GridEditableItem)e.Item; 
            RadNumericTextBox textbox = (RadNumericTextBox)editItem["Number"].Controls[0]; 
            textbox.NumberFormat.AllowRounding = true
            textbox.NumberFormat.DecimalDigits = 0; 
        } 
    } 

-Shinu.
0
Christopher Borys
Top achievements
Rank 1
answered on 09 Nov 2009, 10:17 PM
1. My format already defines a number with no digits after decimal point. 
2. The CS code is something that I wanted to avoid.  Besides, it bumbs with exception:
    Unable to cast object of type 'System.Web.UI.WebControls.TextBox' to type 'Telerik.Web.UI.RadNumericTextBox'.


Tags
Grid
Asked by
Christopher Borys
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Christopher Borys
Top achievements
Rank 1
Share this question
or