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

GridNumericColumn DecimalDigits

5 Answers 965 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pini Usha
Top achievements
Rank 1
Pini Usha asked on 07 May 2011, 07:23 PM
Hi,
I cannot make the DataFormatString to work. i tried to specify  with rounding without rounding with DecimalDigits with DataType="System.Decimal", NumericType="Number" 
and it seems like it just always shows 3dp what ever I do.

I need to make it 4dp.
i read some posts about the edit, but i care only about the display.

Thanks, Pini.

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 May 2011, 09:01 AM
Hello Pini,

You can achieve this by setting DataFormatString property and set the format string. Try the following mark up.

aspx:
<telerik:GridNumericColumn UniqueName="Decimal" NumericType="Number" AllowRounding="false"
 HeaderText="Numeric" DataType="System.Decimal" DataField="decimal"
  DataFormatString="{0:f4}">
</
telerik:GridNumericColumn>

Also check the following documentation which deals with Standard Numeric Format Strings.

If you want the same in Edit mode, then you have to explicitly set the properties. Try the following code snippet by attaching ItemCreated event to your RadGrid.

C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
   {
       if (e.Item is GridEditFormItem   && e.Item.IsInEditMode)
       {
       GridEditFormItem editItem = (GridEditFormItem)e.Item;
       RadNumericTextBox textbox = (RadNumericTextBox)editItem["Decimal"].Controls[0];
       textbox.NumberFormat.AllowRounding = false;
       textbox.NumberFormat.DecimalDigits = 4;
       
   }


Thanks,
Princy.
0
Pini Usha
Top achievements
Rank 1
answered on 10 May 2011, 04:14 AM
No. Still getting 3dp. 
here is the grid header:

<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AutoGenerateColumns="false"
                AllowPaging="True" AllowSorting="false" DataSourceID="ObjectDataSource1" GridLines="None"
                ShowGroupPanel="True" ShowFooter="true" AllowAutomaticDeletes="true" OnItemCommand="RadGrid1_ItemCommand"
                HeaderStyle-HorizontalAlign="Center">
                <ClientSettings AllowDragToGroup="True" ReorderColumnsOnClient="True">
                    <Selecting AllowRowSelect="True" />
                </ClientSettings>
                <FilterItemStyle Width="50px" />
                <ExportSettings IgnorePaging="true" OpenInNewWindow="true" FileName="Transactions"
                    ExportOnlyData="true">
                    <Pdf PageTitle="Transactions" PageWidth="297mm" PageHeight="210mm" FontType="Subset"
                        Producer="Treashares.com" AllowPrinting="true" />
                </ExportSettings>
                <GroupingSettings RetainGroupFootersVisibility="true" ShowUnGroupButton="true" />
                <MasterTableView DataSourceID="ObjectDataSource1" DataKeyNames="Id" ShowGroupFooter="true"
                    CommandItemDisplay="Top">
0
Mira
Telerik team
answered on 12 May 2011, 04:34 PM
Hello Pini,

Could you please send us the declaration of the problematic column?
We will examine it and get back to you with our suggestions for fixing the issue.

Kind regards,
Mira
the Telerik team

Browse the vast support resources we have to jump start 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
Marco Teodoro
Top achievements
Rank 1
answered on 25 Jul 2011, 12:53 PM
hello i'm trying to set a decimal column to show itens using only 3 decimal characters.

How can i achieve this?

here is my code:

<telerik:GridNumericColumn DataField="xxx" DataType="System.Decimal"
                        HeaderText="xxx"  SortExpression="xxx"
                        UniqueName="xxx" DecimalDigits="3">
                    </telerik:GridNumericColumn>

i also tried this:

protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
   {
       if (e.Item is GridEditFormItem   && e.Item.IsInEditMode)
       {
       GridEditFormItem editItem = (GridEditFormItem)e.Item;
       RadNumericTextBox textbox = (RadNumericTextBox)editItem["xxx"].Controls[0];
       textbox.NumberFormat.DecimalDigits = 3;
       
   }
this should be really easy. how can i do it?

best regards, 

Marco

0
Vasil
Telerik team
answered on 28 Jul 2011, 11:52 AM
Hi Marco,

The declaration that you use seems to be correct. Could you confirm that RadGrid1_ItemCreated is registered as event handler for ItemCreated of your grid?
Also could you check what is the type of the data field in the database that you are using? If it is nvarchar(or other string type) instead of 'decimal' (or some other numeric) you will face formatting problems.

Best wishes,
Vasil
the Telerik team

Browse the vast support resources we have to jump start 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.

Tags
Grid
Asked by
Pini Usha
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Pini Usha
Top achievements
Rank 1
Mira
Telerik team
Marco Teodoro
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or