RadNumericTextBox cannot handle properly decimal(18,2)

6 posts, 1 answers
  1. Jacek
    Jacek avatar
    31 posts
    Member since:
    Sep 2011

    Posted 28 Jun 2012 Link to this post

    Hi,

    I can't force following code to work, meaning the values of the decimals are multiplied by 100 and no combination of DecimalSeparator nor DecimalDigits nor Culture setting renders 5.19m as 5,19 (or 5.19 for that matter) - the result is always 519

    <%@ Page Language="C#" AutoEventWireup="true"  %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager runat="server" ID="ScriptManager1">
        </asp:ScriptManager>
        <script type="text/C#" runat="server">
         
            protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
            {
                System.Data.DataTable table = new System.Data.DataTable();
                table.Columns.Add("ID", typeof(int)); 
                           
                table.Columns.Add("pct", typeof(decimal));
                table.Rows.Add(1, 5.19m);
                table.Rows.Add(2, 99.49m);
                table.Rows.Add(3, 19.69m);
                table.Rows.Add(4, 5.99m);
      
                RadGrid1.DataSource = table;
            }
          
        </script>
          <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource">
            <MasterTableView>
                <Columns>
                    <telerik:GridBoundColumn DataField="ID" DataType="System.Int32" HeaderText="ID" UniqueName="ID">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn UniqueName="perComplete" HeaderText="Percent Complete"
                        AllowFiltering="false">
                        <ItemTemplate>
                            <telerik:RadNumericTextBox ID="pct"  runat="server" Text='<%#Eval("pct") %>'  Width="70px">
                                <NumberFormat AllowRounding="false" />                           
                            </telerik:RadNumericTextBox>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
        </div>
        </form>
    </body>
    </html>
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Jun 2012 Link to this post

    Hi,

    I suppose you want to show "," as a DecimalSeperator. If that is the requirement, try setting the following.
    aspx:
    <telerik:RadNumericTextBox ID="pct"  runat="server" Text='<%#Eval("pct") %>'  Width="70px">
    <NumberFormat AllowRounding="false" DecimalSeparator="," />                         
    </telerik:RadNumericTextBox>

    Thanks,
    Shinu.
  3. Jacek
    Jacek avatar
    31 posts
    Member since:
    Sep 2011

    Posted 28 Jun 2012 Link to this post

    As I said before: it does not work.
    Whether you set decimal separator to "." (dot) or "," (comma) the effect is the same: 5.19m is displayed as 519 (just try the code I provided).
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Jun 2012 Link to this post

    Hi,

    I tried the same code in this version(2012, 1, 215, 35) in which decimal separator works as expected. Attached is the screenshot.
    aspx:
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" onneeddatasource="RadGrid1_NeedDataSource">
      <MasterTableView>
        <Columns>
          <telerik:GridBoundColumn DataField="ID" DataType="System.Int32" HeaderText="ID" UniqueName="ID"></telerik:GridBoundColumn>
          <telerik:GridTemplateColumn UniqueName="perComplete" HeaderText="Percent Complete" AllowFiltering="false">
            <ItemTemplate>
               <telerik:RadNumericTextBox ID="pct"  runat="server" Text='<%#Eval("pct") %>'  Width="70px">
                 <NumberFormat AllowRounding="false" DecimalSeparator="," />                         
               </telerik:RadNumericTextBox>
            </ItemTemplate>
         </telerik:GridTemplateColumn>
        </Columns>
     </MasterTableView>
    </telerik:RadGrid>
    C#:
    protected void  RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        System.Data.DataTable table = new System.Data.DataTable();
        table.Columns.Add("ID", typeof(int));
        table.Columns.Add("pct", typeof(decimal));
        table.Rows.Add(1, 5.19m);
        table.Rows.Add(2, 99.49m);
        table.Rows.Add(3, 19.69m);
        table.Rows.Add(4, 5.99m);
        RadGrid1.DataSource = table;
    }

    Thanks,
    Shinu.
  5. Jacek
    Jacek avatar
    31 posts
    Member since:
    Sep 2011

    Posted 29 Jun 2012 Link to this post

    Hi,

    It works or not depending whether server locale is en-US or not (regardless of culture setting for radnumerictextbox control).

    On my local computer (win7 eng, with pl-PL culture) it doesn't work regardless of culture and other settings (see attachment rntb_local), however on Windows Azure server (as I understand it is win2008r2 eng with en-US culture) it works as expected.

    It seems that solution for the problem is to bind data to DbValue instead of Text property (as recommended on http://www.telerik.com/community/forums/aspnet-ajax/grid/radnumerictextbox-culture-compatibility-issues.aspx ), but still, it is a bug.

    Jacek

    PS Telerik UI 2012.2.607.40
  6. Answer
    Vasil
    Admin
    Vasil avatar
    1633 posts

    Posted 02 Jul 2012 Link to this post

    Hello Jacek,

    You should bind the Value or DbValue of the RadNumericTextBox.
    The .Text is String property that represent the specific value in culture depending format.
    If it was possible to make it binding thought the .Text property the DbValue would be never introduced. So it is not a bug, just need to use it the right way.

    Kind regards,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top