How to get values from selected item in a gridview

J

Julia B

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top