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

GridNumericColumn - cant set format

22 Answers 1062 Views
Grid
This is a migrated thread and some comments may be shown as answers.
matt
Top achievements
Rank 1
matt asked on 04 Sep 2008, 06:35 PM
i am using a GridNumericColumn, and i dont want commas to show up in my value. this should be configurable via the DataFormatString property, like so:

    DataFormatString="{0:D}"
    DataFormatString="{0:#####}"

...however, these dont work, my value keeps displaying as: 70,117


whats up?

thanks!
matt

22 Answers, 1 is accepted

Sort by
0
matt
Top achievements
Rank 1
answered on 04 Sep 2008, 06:38 PM
to clarify -- i am referring to the edit-form's textbox display format, not the grid row display.

the value looks fine when listed as a row in the grid. but when its in the edit-form, it has commas.


thanks
matt
0
Shinu
Top achievements
Rank 2
answered on 05 Sep 2008, 06:32 AM
Hi Matt,

Try the following code snippet to achieve the desired scenario.

ASPX:
 <telerik:GridNumericColumn DataField="RollNo" HeaderText="NumCol"  UniqueName="NumCol"></telerik:GridNumericColumn> 
                  

CS:
  protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
 
        if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)) 
        { 
            GridEditableItem edititem = (GridEditableItem)e.Item; 
            RadNumericTextBox numtxtbx = (RadNumericTextBox)edititem["NumCol"].Controls[0]; 
            numtxtbx.NumberFormat.GroupSeparator = ""
        } 
   } 


Thanks
Shinu.
0
matt
Top achievements
Rank 1
answered on 05 Sep 2008, 09:01 PM
hi shinu,

that seems like hack. hooking into that event handler should *not* be necessary to achieve such a basic necessity such as proper numeric formatting.

after all, what is the DataFormatString property for, if not this?

telerik -- is this a known bug w/ the DataFormatString property??


thanks
matt
0
matt
Top achievements
Rank 1
answered on 11 Sep 2008, 04:38 PM
telerik, can you please weigh in on this?

should one not be able to use the NumericColumn's DataFormatString property to format it in both grid-list view, and in edit-form view?

for example, i am using the NumericColumn for a zip code field -- one does not use commas in a zip.

it does not seem logical or reasonable to have to hook into the ItemDataBound event to fix this. is this a bug?

0
Daniel
Telerik team
answered on 11 Sep 2008, 05:40 PM
Hello Matt,

Try the code below:
<telerik:GridNumericColumn DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" UniqueName="UnitPrice" DataType="System.Decimal" DataFormatString="{0:F0}"
</telerik:GridNumericColumn> 

BoundField.DataFormatString Property

All the best,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
John Billiris (JSBBS)
Top achievements
Rank 1
answered on 16 Sep 2008, 12:43 AM
I've encountered the same issue, but with the GridDateTimeColumn. I'm unable to use DataFormatString to format the datetime into just the date component using {0:dd/MM/yyyy}.

I'm using version 2008.1.415.35 of the controls.

Telerik, can you confirm whether this is a bug or confirm which version the functionality behaves as expected?

Thanks !!!!
0
Vlad
Telerik team
answered on 16 Sep 2008, 05:57 AM
Hello John,

Can you try our latest version instead?

Sincerely yours,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Zsolt
Top achievements
Rank 1
answered on 17 Sep 2008, 12:48 PM
Hi,

I have the same problem using 2008.2.826.35.
I'm using programatically created columns, and my numeric columns are set up as follows :

GridNumericColumn gn =

new GridNumericColumn();
gn.DataType = typeof(decimal);
gn.NumericType =
NumericType.Number;
gn.DataFormatString =
"{0:n2}";
gn.ItemStyle.HorizontalAlign =
HorizontalAlign.Right;
gn.MaxLength = maxLength;
gn.DataField = uniqueName;
gn.ReadOnly = (RO ==
"1");

The column will in my case be readonly, and it displays with 4 decimals and is left-justified.
The same approach seems to work perfectly with date-columns.

0
John Billiris (JSBBS)
Top achievements
Rank 1
answered on 18 Sep 2008, 12:01 AM
Vlad,

The latest version appears to have the issue corrected.

Can anyone else confirm?
0
Daniel
Telerik team
answered on 22 Sep 2008, 10:33 AM
Hello John,

Please try the attached sample website and let us know whether it works as expected.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Roman Grygoryshchak
Top achievements
Rank 1
answered on 08 Oct 2008, 09:34 AM
It does not work for readonly columns.
0
Daniel
Telerik team
answered on 10 Oct 2008, 02:42 PM
Hello Roman,

What doesn't work with read-only columns?

Actually the HtmlEncode property can prevent the DataFormatString to work as expected. Since Q2 SP2 release it has been set to false as default.

Greetings,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Roman Grygoryshchak
Top achievements
Rank 1
answered on 13 Oct 2008, 08:36 AM

Formatting of read-only columns doesn’t work in InPlace  edit mode.

 

        <MasterTableView AutoGenerateColumns="False" commanditemdisplay="Top"

            datakeynames="LineNumber" editmode="InPlace">

 

 

                <telerik:GridNumericColumn DataField="OutstandingQuantity"

                    DataType="System.Decimal" HeaderText="Outstanding"

                    SortExpression="OutstandingQuantity" UniqueName="OutstandingQuantity"

                    DataFormatString="{0:n}" ReadOnly="True">

                    <ItemStyle HorizontalAlign="Right" />                   

                </telerik:GridNumericColumn>

 

Add this column to grid, enter edit mode, column will be displayed as  935.59000000000000000000.

 

Telerik version is 2008.2.1001.35.

 

0
Daniel
Telerik team
answered on 15 Oct 2008, 05:21 PM
Hello Roman,

You can customize the embedded RadNumericTextBox as shown below:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    GridDataItem item = e.Item as GridDataItem; 
    if (e.Item.IsInEditMode && item != null
    { 
        RadNumericTextBox textBox = item["OutstandingQuantity"].Controls[0] as RadNumericTextBox; 
        textBox.NumberFormat.AllowRounding = true
        textBox.Type = NumericType.Number; 
    } 

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Roman Grygoryshchak
Top achievements
Rank 1
answered on 17 Oct 2008, 03:52 PM

Thanks. I know how to customise it, but it should work as standard without customisation.

Regards, Roman.

0
Nicolaï
Top achievements
Rank 2
answered on 20 Jul 2009, 07:28 AM
I would agree with that...
The standards should be to not have a NumberFormat-GroupSeparator, which is mathematically incorrect in my opinion.
A property to add a group seperator would make sense. But working around to remove it... :o/
A comma is indicating decimals... A dot would be acceptable too...
3.141=3,141
<> 3141
(For me, it's of the same order of people who say 2+2*2=8 (correct answer is 6); maths 101)
0
Daniel
Telerik team
answered on 23 Jul 2009, 02:41 PM
Hello Nicolai,

Thank you for your suggestion. However I'm afraid we can't afford to alter this behavior due to breaking change concerns. I believe that you will agree with me that the single line that is needed to disable grouping separator, is straightforward enough.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Nicolaï
Top achievements
Rank 2
answered on 24 Jul 2009, 09:45 AM
Yes, I understand such a change would affect existing applications, if they upgraded...
And yes, "the single line that is needed to disable grouping separator, is straightforward enough.".

But, would it be possible to add that property directly for the gridnumericcolumn? (Instead of having to find the autogenerated numerictextbox in the itemdatabound event).
0
Accepted
Daniel
Telerik team
answered on 28 Jul 2009, 03:43 PM
Hello Nicolai,

I passed your suggestion to our developers for future consideration. In the meantime I recommend you use our declarative column editors instead of using code-behind approach:
<telerik:RadGrid ID="RadGrid1" runat="server" ...> 
    <MasterTableView ...> 
        <Columns> 
            <telerik:GridNumericColumn ColumnEditorID="NumericEditor1" DataField="MyValue" /> 
        </Columns> 
    </MasterTableView> 
</telerik:RadGrid> 
<telerik:GridNumericColumnEditor ID="NumericEditor1" runat="server"
    <NumericTextBox> 
        <NumberFormat GroupSeparator="" /> 
    </NumericTextBox> 
</telerik:GridNumericColumnEditor> 

Built-in column editors

As a sign of gratitude for your suggestion I updated your Telerik points.

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Nicolaï
Top achievements
Rank 2
answered on 29 Jul 2009, 06:04 AM
Oh, but I didn't even notice the control GridNumericColumnEditor ..
Guess that way is very straightforward too..
0
sai raghavendra sudha besta
Top achievements
Rank 1
answered on 03 Aug 2009, 03:13 PM
hi,
i am not able to set the dataformatstring for radgrid.

i can see that the format string property is assigned -- as the filter values for each column are getting changed depending upon the column type i have assigned to it. but for some reason none of the data is displayed in correct format.

i cannot set the columns at the design mode it self as, the columns are generated differently for different cases
 my code looks something like this


rgList.Datasource = dt.DefaultView -- this contains the number of columns and the column property.

in columncreted event i am trying to set the dataformatstring property


Dim formatString As String = String.Empty

            If e.Column.ColumnType = "GridBoundColumn" Then
                'when columns are created
                Dim col As GridBoundColumn = CType(e.Column, GridBoundColumn)
                col.HeaderText = colUniqueNames(colIndex)
                col.UniqueName = colUniqueNames(colIndex)
                If Not GetDataType(col.UniqueName) Is Nothing Then
                    col.DataType = GetDataType(col.UniqueName) --- here it sets the property as decimal or integer and so on
                End If
                col.DataFormatString = SetFormatString(col.UniqueName) -- here it assigns the property for format as {0:N} or {0:p}
            End If

            colIndex += 1
            If colIndex = iColCount + 1 Then
                colIndex = 0
            End If

Please do help me out as i am stuck with this problem for long time.

thank you for your help.
Raghav.

0
Manish
Top achievements
Rank 1
answered on 07 Nov 2011, 05:03 AM
Thanks for this. It works!
Tags
Grid
Asked by
matt
Top achievements
Rank 1
Answers by
matt
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Daniel
Telerik team
John Billiris (JSBBS)
Top achievements
Rank 1
Vlad
Telerik team
Zsolt
Top achievements
Rank 1
Roman Grygoryshchak
Top achievements
Rank 1
Nicolaï
Top achievements
Rank 2
sai raghavendra sudha besta
Top achievements
Rank 1
Manish
Top achievements
Rank 1
Share this question
or