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

Setting Number format at code behind

1 Answer 145 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
Benjamin
Top achievements
Rank 2
Iron
Iron
Veteran
Benjamin asked on 06 Jan 2021, 08:59 AM

i would like to know how do i set the NumberFormat in code behind on runtime as my control are created dynamically during Page_Init event.

 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Doncho
Telerik team
answered on 08 Jan 2021, 12:01 PM

Hi Benjamin,

You can use the NormalFormat property of the RadNumericTextBox instance to set the desired formatting rules. For example:
C# code:

protected void Page_Init(object sender, EventArgs e)
{
    DefineNumericTextBox();
}
private void DefineNumericTextBox()
{
    var ntb = new RadNumericTextBox();
    ntb.ID = "RadNumericTextBox1";
    var numberFormat = ntb.NumberFormat;
    numberFormat.DecimalDigits = 2;
    numberFormat.AllowRounding = true;
    numberFormat.GroupSeparator = " ";
    numberFormat.DecimalSeparator = ",";
    PlaceHolder1.Controls.Add(ntb);
}

Markup

<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
Please give let me know if any further questions come up.

Kind regards,
Doncho
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
NumericTextBox
Asked by
Benjamin
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Doncho
Telerik team
Share this question
or