How to get values from selected item in a gridview

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?SnVsaWEgQg==?=

    #1

    How to get values from selected item in a gridview

    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_RowComm and(ByVal sender As Object, ByVal e As
    System.Web.UI.W ebControls.Grid ViewCommandEven tArgs) Handles dgDepts.RowComm and
    If e.CommandName.E quals("Select") Then
    'populate the department edit fields with the data from the
    selected record
    Me.tbDept.Text = Me.dgDepts.Sele ctedRow.Cells(0 ).Text
    End If
    End Sub

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

    I've also tried me.dgDepts.sSle ctedDataKey.Ite m(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

Working...