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

Invalid Cast when assigning a decimal value to the Value property of a telerik:RadNumericTextBox

2 Answers 196 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Cos
Top achievements
Rank 1
Cos asked on 23 Oct 2008, 03:49 PM

When I Try: 

<telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" Culture="English (United States)" Type="Currency" Font-Size="Smaller" Height="8px" Width="75px" IncrementSettings-Step=".01" AutoPostBack="false" ShowSpinButtons="true" Value='3.49' >

Everything works 'fine', but when I attempt to data bind to the value property (asp.net/.net 3.5) like :

<telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" Culture="English (United States)" Type="Currency" Font-Size="Smaller" Height="8px" Width="75px" IncrementSettings-Step=".01" AutoPostBack="false" ShowSpinButtons="true" Value='<%# Eval("CurrentPrice") %>' >

I get "Specified cast is not valid." as a runtime exception. The type for the CurrentPrice Property is Decimal, since the "Type" property for this control is "Currency" (and it is called a "NUMERIC" text box) I expect a decimal to work.

Any help would be greatly appreciated!

Cos

 

 

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 23 Oct 2008, 04:53 PM
Hello Cos,

You Eval expression probably returns a value of type object. Try to cast it as double:
Value='<%# Convert.ToDouble(Eval("CurrentPrice")) %>' 




or

Value='<%# double.Parse(Eval("id").ToString()) %>' 

Kind regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Cos
Top achievements
Rank 1
answered on 23 Oct 2008, 04:58 PM
Thanks Daniel,

Actually, it evaluates to type of "decimal" (I tested for this).
 The cast 'ToDouble' works. I guess I'm just surprised that Decimal doesn't work, but as I have it working now I'm not worried about it...

Thanks for your help,

Cos
Tags
General Discussions
Asked by
Cos
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Cos
Top achievements
Rank 1
Share this question
or