Results 1 to 6 of 6

Thread: [Resolved] GridView selection problem

  1. #1

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    [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.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  3. #3

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    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.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  5. #5

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Re: [Resolved] GridView selection problem

    I have posted my code and attempt under a new topic.

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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
  •  



Click Here to Expand Forum to Full Width