Invalid Cast Exception in asp template

10 posts, 0 answers
  1. Mark
    Mark avatar
    52 posts
    Member since:
    Sep 2007

    Posted 20 Feb 2008 Link to this post

    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

  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 22 Feb 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rich
    Rich avatar
    65 posts
    Member since:
    Jul 2012

    Posted 31 Jul 2009 Link to this post

    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.
  5. Rich
    Rich avatar
    65 posts
    Member since:
    Jul 2012

    Posted 31 Jul 2009 Link to this post

    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
    
  6. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 05 Aug 2009 Link to this post

    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.
  7. Chandra Pottipati
    Chandra Pottipati avatar
    5 posts
    Member since:
    Aug 2012

    Posted 18 Nov 2009 Link to this post

    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

     

     

     

  8. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 19 Nov 2009 Link to this post

    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.
  9. Chandra Pottipati
    Chandra Pottipati avatar
    5 posts
    Member since:
    Aug 2012

    Posted 19 Nov 2009 Link to this post

    Thank you , This sounds like a better option than my setting Text property workaround.

    Chandra.
  10. Paul
    Paul avatar
    2 posts
    Member since:
    Jan 2014

    Posted 22 Jan 2014 Link to this post

    Just Change Value to text Mean from
     Value='<%# Eval("goalHours") %>' AutoPostBack="true" Width="40px">

    TO

     Text='<%# Eval("goalHours") %>' AutoPostBack="true" Width="40px">
  11. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 22 Jan 2014 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017