TelerikDeveloper.com

TelerikDeveloper.com

sgray128 1/16/2015 10:04:09 AM

ASP.NET - RadNumericTextBox

Code samples for the RadNumericTextBox


 

 

<telerik:RadNumericTextBox ID="numMasterNumber" runat="server" 
    EmptyMessage="Enter the new master number" 
    NumberFormat-DecimalDigits="0">
</telerik:RadNumericTextBox>

 

RadNumericTextBox restricts user input to numeric values. It shares the common properties of all RadInput controls, including support for skins, styles for different states, empty message support, conditional postback on text change, flexible caret and button positioning, labels, and so on.

Specifying the Numeric Type
RadNumericTextBox support three numeric types that can be switched via its Type property. The numeric type controls the formatting of the numeric text box's value when it does not have focus. When the text box has focus (during editing), it displays the actual number, without any special formatting.
Number: When the Type property is "Number", the value is formatted as a simple number when the numeric text box does not have focus:
Currency: When the Type property is "Currency", the value is formatted as a currency value when the numeric text box does not have focus:
Percent: When the Type property is "Percent", the value is formatted as a percentage when the numeric text box does not have focus:

Representing Negative Values
When the numeric text box contains a negative value, it can notify the user of this in two ways.
The representation of the negative value is usually formatted in a special way, such as using the minus sign ("-") or enclosing the value in parentheses. This representation is determined by the Type and Culture properties, but can be overridden by the NumberFormat.NegativePattern property.
The numeric text box can change the display to signal a negative number (for example, the text is red instead of black). To change the display for negative numbers, use the NegativeStyle property. NegativeStyle is one of the RadInput style properties, but it is only available for RadNumericTextBox.

Increment Controls
In addition to typing numbers directly into the numeric text box, you can also allow users to increment or decrement the current value using the arrow keys, mouse wheel, or spin buttons.
To add spin buttons to the control, set the ShowSpinButtons property to True. You can use the ButtonsPosition property to position the spin buttons on the left or the right side of the text area:

Limiting the Range
Use the MaxValue and MinValue properties to specify a range for the numeric text box. If the user tries to enter a value that is greater than the value of the MaxValue property, the numeric text box automatically changes the value to MaxValue. Similarly, if the user tries to enter a value that is less than the value of the MinValue property, the numeric text box automatically changes the value to MinValue.

Numeric Text Box Value
RadNumericTextBox uses the Value property to represent its value.

DataType
The DataType property defines the type of object that is used to wrap the DbValue property. This property is designed to be used when RadNumericTextBox is embedded into a grid or other data-bound control. By default, its value is set to Double.

NumberFormat
The NumberFormat property controls how RadNumericTextBox formats its value. The format that you specify in this way is applied when the numeric text box does not have focus. During editing, RadNumericTextBox always uses the actual number.

Note
The value of NumberFormat takes precedence over both the Type property and the Culture property.

NumberFormat is a composite property with the following sub-properties:
AllowRounding Specifies whether the value is rounded (when set to true) or truncated ( when set to false ) when the number of decimal places exceeds the value of DecimalDigits.
KeepNotRoundedValue Specifies whether the control will keep its not rounded value (when set to true) and show it when it is focused. Otherwise (when set to false) the old behavior is preserved, where the actual value of the control is the rounded value. By default this property is set to false.
KeepTrailingZerosOnFocus Specifies whether the control will keep its zero numbers(when set to true) and show them when it is focused, according to the DecimalDigits setting. Otherwise (when set to false) the old behavior is preserved - the control will not display decimal zeros when focused. By default this property is set to false.
DecimalDigits Specifies the number of digits that are displayed after the decimal separator.
DecimalSeparator Specifies the character that separates the fractional portion of a number.
GroupSeparator - Specifies the character that separates each group of digits.
GroupSizes Specifies the number of digits in each group, starting from the decimal separator.
NegativePattern Specifies the pattern for formatting negative values. (See below for details on formatting patterns.)
PositivePattern Specifies the pattern for formatting positive values. (See below for details on formatting patterns.)
ZeroPattern Specifies the pattern for formatting the value when it equals zero. (See below for details on formatting patterns.)

Formatting patterns
Formatting patterns are strings that control the placement of elements when formatting a numeric value. A Formatting pattern consists of the special symbol n, which represents the number, plus any literal characters that are part of the formatted value. Typically, the literal values are characters such as the negative sign ("-"), a currency symbol ("$"), parentheses, and so on.

Note The characters other than n in a formatting pattern are literal symbols. If you use the dollar sign ("$") as a currency symbol, for example, currency values are formatted using that symbol regardless of the value of the Culture property.