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

Error after upgrade - radgrid-InvalidCastException was unhandled by user code

3 Answers 8 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 31 Jul 2014, 09:43 PM
This application was previously created in VS2008 and the last version of Telerik ASP.NET AJAX Controls in it was 2009.2 701.  I was able to upgrade the Telerik controls to 2012.3.1016 and VS to 2010 and get the web application to work without problems.  When I tried to jump to 2014.2 618 and VS 2013 I received this error.  With some difficulty I was able to restore back to the 2012.3.1016 point in my application.  I thought if I tried to edge towards the 2014 version of the controls by going through a 2013 version, I might be able to make it without this error.  No such luck. 

The column in the code listed below is hidden.  We have found that if it is made visible, then the code works.

The error message content is "Message=Conversion from string " " to type 'Integer' is not valid.".  Below is the sub, with the line bolded, where the error occurs:
 
Private Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGridGrants.ItemCommand
    '-- Navigate to the grant edit form (edit mode)
    Dim theGrantID As Integer = e.Item.Cells(GridColumns.GrantID).Text
    Select Case e.CommandName
        Case "View"
            '-- Edit the selected link
            Response.Redirect("GrantEdit.aspx?Action=View&GrantID=" + theGrantID.ToString)
        Case "Edit"
            '-- Edit the selected link
            Response.Redirect("GrantEdit.aspx?Action=Edit&GrantID=" + theGrantID.ToString)
    End Select
End Sub

Could someone shed some light on this and perhaps a solution?  I would like to upgrade the controls all the way to the current version, if I can find a solution.  Thanks for your help.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 01 Aug 2014, 05:15 AM
Hi Alex,

I guess you are trying to get the value of a row which is selected, please try the following code snippet instead of your highlighted code.

VB:
Dim dataItem As GridDataItem = DirectCast(e.Item, GridDataItem)
Dim theGrantID As Integer = Convert.ToInt16(dataItem("ColumnUniqueName").Text)

Please take a look into this documentation for more help: Accessing Cells and Rows

Thanks,
Princy
0
Alex
Top achievements
Rank 1
answered on 01 Aug 2014, 06:06 PM
At first, I wasn't able to get your snippet to work either.  When I got to your second line I receive a FormatException stating "Input string was not in a correct format." 

Although I did look over the documentation you pointed me to, and tried to look through some of the other documentation on the radgrid I didn't find the solution there or my comprehension didn't see a solution.

I continued to search for an answer and stumbled across a post that helped me.  Part of his answer said to use the Display attribute instead of Visible.  When I made the change and tried it my application worked, with both your snippet and my original code!  I imagine if you had seen the Source on my aspx page, you probably could have pointed me in that direction also.  I really appreciate your effort to help me as I am sort of a novice with these controls.  I inherited an application to maintain that a contractor built for us and I am learning a little more about the controls as I have to make enhancements but still have a long ways to go.  Thanks again for your time!
0
Maria Ilieva
Telerik team
answered on 06 Aug 2014, 02:13 PM
Hi Alex,

I suppose that the issue you are facing is caused by e breaking change made for RadGrid's ViewState optimization.

See the sticky thread below for more information on this matter:
http://www.telerik.com/forums/breaking-change-hidden-column-cell-text-is-not-persisted-in-viewstate

Regards,
Maria Ilieva
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Alex
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or