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

Invalid Cast Exception in asp template

9 Answers 364 Views
Input
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 20 Feb 2008, 06:06 PM
Greetings

I'm using the numericInput control inside an asp.net DetailsView template field.   I can insert and view record details fine, but when I try to edit a record I get an InvalidCastException error, specified cast is not valid.  The first thing listed in the troubleshooting tips below the error is "when casting from a number the value must be less than infinity".  This process works fine if I switch out the numericInput controls with plain textbox controls.

I've confirmed that my asp:parameters are all the same datatype for insert and edit, I've used the exact same control (drag-n-drop copy from insert template to edit template), and I've confirmed the values are valid and non-null in the database for that field.

Here's the template code:

<

asp:TemplateField HeaderText="Earned Income " SortExpression="earned_inc_total">

<EditItemTemplate>
        
<telerik:RadNumericTextBox ID="radEarnedIncTotal" runat="server" Culture="English (United States)" MinValue="0" Type="Currency" Value='<%# Bind("earned_inc_total") %>' Width="125px">
        
<NumberFormat AllowRounding="True" />
        
</telerik:RadNumericTextBox>
 
</EditItemTemplate>

<InsertItemTemplate>
    <telerik:RadNumericTextBox ID="radEarnedIncTotal" runat="server" Culture="English (United States)" MinValue="0" Type="Currency" Value='<%# Bind("earned_inc_total") %>' Width="125px">
    
<NumberFormat AllowRounding="True" />
    
</telerik:RadNumericTextBox>
</InsertItemTemplate>

Thanks
Mark

9 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 22 Feb 2008, 05:05 PM
Hello Mark,

The problem could be related to some property value that is not supported or some non properly closed tag in the ConfigFile.xml file. Could you check your Config file for this error and also verify that you do not have double entries in it.
If you are not able to isolate the problem it will be very helpful if you could post the
Stack Trace details in the forum.

Kind regards,
Maria Ilieva
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Rich
Top achievements
Rank 1
answered on 31 Jul 2009, 01:17 PM
Hi, i'm getting this same error.

what config file are you talking about??

I'm using a formview.. and the tag looks like:

<

 

telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" Type="Number" MaxLength="5" MinValue="0" NumberFormat-DecimalDigits="0" Value='<%# Bind("currencyQuantum") %>'></telerik:RadNumericTextBox>

 


The returned value is 1.. and still getting an exception "Must be less than infinity"?? I've tried setting the datatype etc.. same error.
0
Rich
Top achievements
Rank 1
answered on 31 Jul 2009, 01:19 PM
Stack Trace:

[InvalidCastException: Specified cast is not valid.]
   ASP.commodity_default_aspx.__DataBinding__control65(Object sender, EventArgs e) in d:\ProjectSourceCode\Propurchaser2\branches\M2\Administration\Commodity\default.aspx:341
   System.Web.UI.Control.OnDataBinding(EventArgs e) +99
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +92
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.Control.DataBindChildren() +211
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.Control.DataBindChildren() +211
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.Control.DataBindChildren() +211
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.Control.DataBindChildren() +211
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
   System.Web.UI.WebControls.FormView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +1461
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
   System.Web.UI.WebControls.FormView.PerformDataBinding(IEnumerable data) +12
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   System.Web.UI.WebControls.FormView.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
   System.Web.UI.WebControls.FormView.EnsureDataBound() +166
   System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e) +22
   System.Web.UI.Control.PreRenderRecursiveInternal() +80
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
0
Pavlina
Telerik team
answered on 05 Aug 2009, 04:34 PM
Hi Rich,

I am afraid that the provided information is not enough to determine what have caused the unexpected behavior. In order to find a quick solution/fix of this problem I will ask you to open a formal support ticket and send us a small working project, demonstrating your setup, for additional testing and debugging.

Kind regards,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Chandra Pottipati
Top achievements
Rank 1
answered on 18 Nov 2009, 04:24 PM

I had the same problem. Instead of setting the Value property of the RadNumericTextbox, set the Text property.
example
<EditItemTemplate<telerik:RadNumericTextBox runat="server" ID="tbAmount" Text='<%#Bind("Amount")%>' Type="Currency" DataType="DbValue" > </telerik:RadNumericTextBox</EditItemTemplate>

Chandra

 

 

 

0
Pavlina
Telerik team
answered on 19 Nov 2009, 10:51 AM
Hello Chandra,

With RadNumericTextbox and RadDateInput, use the DbValue and DbSelectedDate properties rather than the Value and SelectedDate properties. The "Db" properties differ from the counterparts you usually use in that they do not throw an exception if the new value is null, string, or DBNull. Setting a DbNull value will internally revert the DbNull to an empty value.
More information is available here:
Using RadInput Controls Inside Data-Bound Controls

Sincerely yours,
Pavlina
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
Chandra Pottipati
Top achievements
Rank 1
answered on 19 Nov 2009, 03:43 PM
Thank you , This sounds like a better option than my setting Text property workaround.

Chandra.
0
Paul
Top achievements
Rank 1
answered on 22 Jan 2014, 03:14 PM
Just Change Value to text Mean from
 Value='<%# Eval("goalHours") %>' AutoPostBack="true" Width="40px">

TO

 Text='<%# Eval("goalHours") %>' AutoPostBack="true" Width="40px">
0
Vasil
Telerik team
answered on 22 Jan 2014, 04:11 PM
Hello Paul,

Using the Text directly is generally not recommended, because it is current culture depended approach.
The Text property of RadNumericTextBox always keeps the value in culture independent format like "123.45". If the value in your database is (Double)123.45 , it will be automatically cast to string when you Eval it. If the current culture use comma for decimal separator, the "123,45" will be assigned to the .Text property, and it will eventually fail to parse, and display either 123 or 12345 as result.

Using directly the Text could be stable only if the column in your database is culture-independent string. Anyway, if your server is with EN-US culture it will probably work with the .Text property, but I have to warn the forum members, because they servers can be all around the world.

The DbValue property of RadNumericTextBox will correctly bind to double, int, decimal, DbNull, TimeSpan, string representation of number in current culture or independent culture.
It can also make the DbValueFactor property to work if you bind value in percent or permille and you want to adjust the display of that value.

Regards,
Vasil
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Input
Asked by
Mark
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Rich
Top achievements
Rank 1
Pavlina
Telerik team
Chandra Pottipati
Top achievements
Rank 1
Paul
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or