How to get values from selected item in a gridview

Discussion in 'ASP .Net' started by Julia B, Oct 8, 2008.

  1. Julia B

    Julia B Guest

    Hi all, just as I'd got the hang of datagrids in 1.1 they change to gridviews
    and everything is done differentley...... I'm really stuck so help would be
    appreciated!

    I've got a gridview which has a select command. When the user clicks the
    select command I want the data from the selected row to be pasted into some
    controls/fields I have, the problem is that I can't seem to be able to get
    the data, here's one of the variations i've tried:

    Private Sub dgDepts_RowCommand(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewCommandEventArgs) Handles dgDepts.RowCommand
    If e.CommandName.Equals("Select") Then
    'populate the department edit fields with the data from the
    selected record
    Me.tbDept.Text = Me.dgDepts.SelectedRow.Cells(0).Text
    End If
    End Sub

    I get an error message at Me.dgDepts.SelectedRow.Cells(0).Text as it's
    showing as nothing.

    I've also tried me.dgDepts.sSlectedDataKey.Item(0).ToString but get the same
    message (although I'm not sure I really understand this new datakey lark).

    I've searched high and low to get examples of how to do this and have found
    lots but nothing that matches what I need to do.

    Any clues greatly appreciated.
    Julia
     
    Julia B, Oct 8, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dst
    Replies:
    0
    Views:
    569
  2. Iain
    Replies:
    3
    Views:
    960
  3. Robert Smith
    Replies:
    1
    Views:
    411
    Mark Rae [MVP]
    Mar 9, 2008
  4. mldardy
    Replies:
    0
    Views:
    995
    mldardy
    Sep 28, 2010
  5. nate

    gridview paging selected item

    nate, Jul 18, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    169
Loading...

Share This Page