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

RadNumericTextBox cannot handle properly decimal(18,2)

5 Answers 115 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jacek
Top achievements
Rank 1
Jacek asked on 28 Jun 2012, 10:57 AM
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>

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Jun 2012, 11:15 AM
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.
0
Jacek
Top achievements
Rank 1
answered on 28 Jun 2012, 12:52 PM
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).
0
Shinu
Top achievements
Rank 2
answered on 29 Jun 2012, 04:03 AM
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.
0
Jacek
Top achievements
Rank 1
answered on 29 Jun 2012, 01:49 PM
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
0
Accepted
Vasil
Telerik team
answered on 02 Jul 2012, 11:28 AM
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.
Tags
General Discussions
Asked by
Jacek
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jacek
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or