GridNumericColumn - cant set format

23 posts, 1 answers
  1. matt
    matt avatar
    259 posts
    Member since:
    Oct 2007

    Posted 04 Sep 2008 Link to this post

    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
  2. matt
    matt avatar
    259 posts
    Member since:
    Oct 2007

    Posted 04 Sep 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Sep 2008 Link to this post

    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.
  5. matt
    matt avatar
    259 posts
    Member since:
    Oct 2007

    Posted 05 Sep 2008 Link to this post

    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
  6. matt
    matt avatar
    259 posts
    Member since:
    Oct 2007

    Posted 11 Sep 2008 Link to this post

    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?

  7. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 11 Sep 2008 Link to this post

    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.
  8. John Billiris (JSBBS)
    John Billiris (JSBBS) avatar
    27 posts
    Member since:
    Mar 2007

    Posted 15 Sep 2008 Link to this post

    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 !!!!
  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 16 Sep 2008 Link to this post

    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.
  10. Zsolt
    Zsolt avatar
    16 posts
    Member since:
    Jan 2007

    Posted 17 Sep 2008 Link to this post

    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.

  11. John Billiris (JSBBS)
    John Billiris (JSBBS) avatar
    27 posts
    Member since:
    Mar 2007

    Posted 17 Sep 2008 Link to this post

    Vlad,

    The latest version appears to have the issue corrected.

    Can anyone else confirm?
  12. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 22 Sep 2008 Link to this post

    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.
  13. Roman Grygoryshchak
    Roman Grygoryshchak avatar
    6 posts
    Member since:
    Sep 2008

    Posted 08 Oct 2008 Link to this post

    It does not work for readonly columns.
  14. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 10 Oct 2008 Link to this post

    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.
  15. Roman Grygoryshchak
    Roman Grygoryshchak avatar
    6 posts
    Member since:
    Sep 2008

    Posted 13 Oct 2008 Link to this post

    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.

     

  16. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 15 Oct 2008 Link to this post

    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.
  17. Roman Grygoryshchak
    Roman Grygoryshchak avatar
    6 posts
    Member since:
    Sep 2008

    Posted 17 Oct 2008 Link to this post

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

    Regards, Roman.

  18. Nicolaï
    Nicolaï avatar
    160 posts
    Member since:
    Apr 2008

    Posted 20 Jul 2009 Link to this post

    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)
  19. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 23 Jul 2009 Link to this post

    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.
  20. Nicolaï
    Nicolaï avatar
    160 posts
    Member since:
    Apr 2008

    Posted 24 Jul 2009 Link to this post

    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).
  21. Answer
    Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 28 Jul 2009 Link to this post

    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.
  22. Nicolaï
    Nicolaï avatar
    160 posts
    Member since:
    Apr 2008

    Posted 29 Jul 2009 Link to this post

    Oh, but I didn't even notice the control GridNumericColumnEditor ..
    Guess that way is very straightforward too..
  23. sai raghavendra sudha besta
    sai raghavendra sudha besta avatar
    10 posts
    Member since:
    Aug 2009

    Posted 03 Aug 2009 Link to this post

    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.

  24. Manish
    Manish avatar
    2 posts
    Member since:
    Nov 2010

    Posted 06 Nov 2011 Link to this post

    Thanks for this. It works!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017