add zero in numerictextbox field

2k Views Asked by At

I have numeric text box like that

<telerik:radnumerictextbox showspinbuttons="true" incrementsettings-interceptarrowkeys="true" incrementsettings-interceptmousewheel="true" labelwidth="120px" runat="server" id="ddStartHour" width="100px" MaxLength="2" MaxValue="12" Value="0" MinValue="0" CssClass="app-input" DataType="System.Integer" >

    <NumberFormat  DecimalDigits="0" />

</telerik:radnumerictextbox>

Now my numbers can be 0,1,2,3,4,5,6,7,8,9,10,11,12.

But I want to add zero before the numbers which number is less than 10. So I want to show my numbers like 00,01,02,03,04,05,06,07,08,09,10,11,12.

How can I do that?

THX.

2

There are 2 best solutions below

0
Diego López On BEST ANSWER

you can achieve this through the client side methods of the RadNumericTextBox Client Object, try this:

<script type="text/javascript">
function formatValue(sender, args) {
    var intCurrentValue = sender.get_value();
    if (intCurrentValue < 10) {
        sender.set_textBoxValue("0"+intCurrentValue);
    }
}
</script>
<telerik:radnumerictextbox showspinbuttons="true" incrementsettings-interceptarrowkeys="true" incrementsettings-interceptmousewheel="true" labelwidth="120px" runat="server" id="ddStartHour" width="100px" MaxLength="2" MaxValue="12" Value="00" MinValue="0" CssClass="app-input" DataType="System.Integer" >
    <ClientEvents OnBlur="formatValue" OnLoad="formatValue" OnValueChanged="formatValue"  />
    <NumberFormat  DecimalDigits="0"  />
</telerik:radnumerictextbox>

In this example the formatValue method is called whenever the value is changed or the control lose focus, you can use the client side api of Telerik for a custom function since formatting numeric values in telerik does not provide a way to format the value with a regular expression or so.

0
ಅನಿಲ್ On

In Kendo Please add the Format "0#".