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

RadNumericTextBox - only double?

7 Answers 658 Views
Input
This is a migrated thread and some comments may be shown as answers.
wnl
Top achievements
Rank 1
wnl asked on 26 Oct 2009, 09:20 AM
Hi,
I'm using RadNumericTextBox and I set DataType = System.Decimal.
But in code the value is double from this TextBox.
Is it normal?

7 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 26 Oct 2009, 10:41 AM
Hello Jaromin,

I confirm this is expected - RadNumericTextBox internally uses type "double" regardless of the DataType setting. Whatever the value type you assigned, it will be parsed to double? (if possible).

Furthermore, the Value property returns double? so it can't return decimal or another type.

Please let me know if you need more information.

Kind regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
wnl
Top achievements
Rank 1
answered on 26 Oct 2009, 10:58 AM
Ok.
In which cases we can use DataType? Any example?
0
Daniel
Telerik team
answered on 29 Oct 2009, 01:30 PM
Hello Jaromin,

DataType property determines what will be the data type that comes from DbValue property. Example:

Sample DataTable data source:
...
table.Columns.Add("ID", typeof(Decimal));

Sample setup:
<telerik:GridTemplateColumn>
   <ItemTemplate>
      <telerik:RadNumericTextBox ID="rntb1" DataType="System.Decimal" runat="server" DbValue='<%# Bind("myValue") %>' />
   ....

If you examine the DbValue property on ItemDataBound, you will notice that the data type is Decimal
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        string dataType = (e.Item.FindControl("rntb1") as RadNumericTextBox).DbValue.GetType().ToString();
        RadAjaxPanel1.Alert(dataType);
    }
}

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
wnl
Top achievements
Rank 1
answered on 20 Nov 2009, 01:46 PM
Thanks Daniel.
0
maina
Top achievements
Rank 1
answered on 28 Sep 2010, 05:15 PM

The datatype shows as decimal but still I am not able to use it as a decimal unless I do a convert.
eg:

 

 

 

<telerik:RadNumericTextBox ID="rntCalories" runat="server" MaxLength="9"

 

 

 

NumberFormat-DecimalDigits="3" Width="110px" EnabledStyle-HorizontalAlign="Right" Type="Number" DataType="System.Decimal">

 

 

 

 

In c# page I have
decimal val = Convert.ToDecimal(this.rntCalories.DbValue)

because DbValue is a is an object. Is there any other way to use directly?





0
Cori
Top achievements
Rank 2
answered on 30 Sep 2010, 04:39 PM
Hello Maina,

You will always have to convert the value into Decimal. There is no way to use it directly.

I hope that helps.
0
maina
Top achievements
Rank 1
answered on 30 Sep 2010, 11:32 PM
Thanks! Cori. I will just do the convert.
Tags
Input
Asked by
wnl
Top achievements
Rank 1
Answers by
Daniel
Telerik team
wnl
Top achievements
Rank 1
maina
Top achievements
Rank 1
Cori
Top achievements
Rank 2
Share this question
or