|
-
Jul 14th, 2008, 09:19 AM
#1
Thread Starter
Fanatic Member
[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)
Last edited by snufse; Jul 15th, 2008 at 08:55 AM.
-
Jul 14th, 2008, 01:14 PM
#2
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.
-
Jul 15th, 2008, 06:51 AM
#3
Thread Starter
Fanatic Member
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.
-
Jul 15th, 2008, 10:06 AM
#4
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.
-
Jul 15th, 2008, 10:11 AM
#5
Thread Starter
Fanatic Member
Re: [Resolved] GridView selection problem
I have posted my code and attempt under a new topic.
-
Jul 15th, 2008, 12:54 PM
#6
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|