petersza
10-30-03, 07:54 PM
I have set up a DataGrid with an EditCommandColumn. When the user clicks the update button, the associated event procedure runs. Of course, one of the things that needs to be done in that procedure is to get the data that is to be updated from the current row of the grid. I am miserably confused about how to do this after reading several books, searching google, and so on. I can get the ID, which is an integer, like this:
Public Sub dgTrailers_Update(ByVal Sender As Object, ByVal e as DataGridCommandEventArgs)
Dim ID as Integer = e.Item.Cells(0).Text
End Sub
This works without any errors. But this doesn't work for the other columns, one of which is also an integer (!) and the other a string. Here's one attempt to get the data in the second column (Integer):
Public Sub dgTrailers_Update(ByVal Sender As Object, ByVal e as DataGridCommandEventArgs)
Dim TrailerYear as Integer = e.Item.Cells(1).Text
End Sub
I get this error: Input string was not in a correct format.
Here's another attempt to get the same data:
Public Sub dgTrailers_Update(ByVal Sender As Object, ByVal e as DataGridCommandEventArgs)
Dim TrailerYear as Integer = CType(e.Item.Cells(1).Controls(0), TextBox).Text
End Sub
I get this error: Specified cast is not valid.
Now, here's a similar attempt to get the String value in the third column, which gives me the same "Specified cast is not valid" error.
Public Sub dgTrailers_Update(ByVal Sender As Object, ByVal e as DataGridCommandEventArgs)
Dim TrailerMake as String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
End Sub
I'd like to know:
1. Specifically, what am I doing wrong in this case?
2. In general, what is the proper syntax for retrieving data for the different data types? Can anyone provide a comprehensive explanation of this, or point me to somewhere that explains it clearly so that the day that I need to grab some other kind of data from the grid, I will be able to?
Thank you!
Peter
Public Sub dgTrailers_Update(ByVal Sender As Object, ByVal e as DataGridCommandEventArgs)
Dim ID as Integer = e.Item.Cells(0).Text
End Sub
This works without any errors. But this doesn't work for the other columns, one of which is also an integer (!) and the other a string. Here's one attempt to get the data in the second column (Integer):
Public Sub dgTrailers_Update(ByVal Sender As Object, ByVal e as DataGridCommandEventArgs)
Dim TrailerYear as Integer = e.Item.Cells(1).Text
End Sub
I get this error: Input string was not in a correct format.
Here's another attempt to get the same data:
Public Sub dgTrailers_Update(ByVal Sender As Object, ByVal e as DataGridCommandEventArgs)
Dim TrailerYear as Integer = CType(e.Item.Cells(1).Controls(0), TextBox).Text
End Sub
I get this error: Specified cast is not valid.
Now, here's a similar attempt to get the String value in the third column, which gives me the same "Specified cast is not valid" error.
Public Sub dgTrailers_Update(ByVal Sender As Object, ByVal e as DataGridCommandEventArgs)
Dim TrailerMake as String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
End Sub
I'd like to know:
1. Specifically, what am I doing wrong in this case?
2. In general, what is the proper syntax for retrieving data for the different data types? Can anyone provide a comprehensive explanation of this, or point me to somewhere that explains it clearly so that the day that I need to grab some other kind of data from the grid, I will be able to?
Thank you!
Peter