[Resolved] GridView selection problem
I am selecting data from 2 cells in my GridView. See code blelow:
The value from Cell(0) get selected Ok, get error on Cell(5), last line in code.
Error is:
Conversion from string "" to type 'Integer' is not valid.
Code:
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim mySelectedRow As GridViewRow = GridView2.Rows(index)
Dim mySelectedCell As TableCell
mySelectedCell = mySelectedRow.Cells(0)
Dim mySelectedDate As DateTime = CDate(mySelectedCell.Text) & " 00:00:00"
mySelectedCell = mySelectedRow.Cells(5)
Dim mySelectedNote As String = ToString(mySelectedCell.Text)
If I change my code to this:
Code:
Dim SelectedNote As String = mySelectedCell.Text.ToString
I do not get an error, but the value for "SelectedNote" is blank. Could this be due to the field being defined as a Button Field?
Cell 0: 6/30/2008
Cell 1: 5101
Cell 2: Y
Cell 3: 697.66
Cell 4: TN
Cell 5: 1.5" lift 1/1 68+92-114+37 1
Fields in cells 0 - 4 are bound fields
Field 5 is a button field (click able)
Re: GridView selection problem
Try doing an int.TryParse. It will return a true or false depending on whether the string was a valid number or not. Based on that value you can proceed or choose not to.
Re: GridView selection problem
When I changed the button field to bound field I was able to get the value of cell 5. Does anyone know if a botton field does not allow value from a cell to be retrieved. Thank you.
Re: [Resolved] GridView selection problem
If it was a button field, then you would have needed to get the button control, cast it, and then read its text property.
Re: [Resolved] GridView selection problem
I have posted my code and attempt under a new topic.
Re: [Resolved] GridView selection problem
Would've been perfectly acceptable to continue here, but that's fine.
For future searchers: http://www.vbforums.com/showthread.php?t=531599