Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Datagrid: get value from the row selected by user

Reply
Thread Tools

Datagrid: get value from the row selected by user

 
 
Northern
Guest
Posts: n/a
 
      07-22-2003
What I want to do is to retrive the value from the row
that was selected by uesr. I added the "Select" command
column and linked the select event to one of my method by
setting my DataGrid's attribute:
OnSelectedIndexChanged="OnSelectRow"

Now comes the problem. Even though I can invoke this
OnSelectRow method, I can only do so when I have the
following signiture:
Protected Sub OnSelectRow(ByVal sender As Object, _
ByVal e As System.EventArgs)

This doesn't help me because System.EventArgs doesn't give
me what I need.

Can somebody help me on how to do this? What signiture
should I use in this case?

Thanks
 
Reply With Quote
 
 
 
 
Greg Burns
Guest
Posts: n/a
 
      07-22-2003
I think you want to use grid.SelectedIndex or grid.SelectedItem in this
event instead of the generic EventArgs.

If you defined a DataKeyField attribute on your grid you can do something
like so instead the event:

Dim KeyID = Ctype(grid.DataKeys(grid.SelectedIndex), integer)


Another approach is to use the ItemCommand event instead (which gets fired
prior to the more specific SelectedIndexChanged). Note: in the ItemCommand
event your grid.SeletecIndex is the previously selected row, not the current
one (it doesn't change until SelectedIndexChanged fires).

Protected Sub HandleCommand(ByVal s As Object, ByVal e As
DataGridCommandEventArgs) Handles grid.ItemCommand

If e.CommandName = "Select" Then
Dim KeyID As Integer = CType(grid.DataKeys(e.Item.ItemIndex),
Integer)
End If

End Sub

HTH,
Greg


"Northern" <(E-Mail Removed)> wrote in message
news:025601c3507a$8279fa10$(E-Mail Removed)...
> What I want to do is to retrive the value from the row
> that was selected by uesr. I added the "Select" command
> column and linked the select event to one of my method by
> setting my DataGrid's attribute:
> OnSelectedIndexChanged="OnSelectRow"
>
> Now comes the problem. Even though I can invoke this
> OnSelectRow method, I can only do so when I have the
> following signiture:
> Protected Sub OnSelectRow(ByVal sender As Object, _
> ByVal e As System.EventArgs)
>
> This doesn't help me because System.EventArgs doesn't give
> me what I need.
>
> Can somebody help me on how to do this? What signiture
> should I use in this case?
>
> Thanks



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get field value of selected row in gridview? Dan ASP .Net 3 05-30-2009 11:37 AM
Want to add row under selected row of gridview ujjc001@gmail.com ASP .Net Building Controls 1 02-16-2007 07:14 PM
Selected Row Only GridView Row Visible? needin4mation@gmail.com ASP .Net Web Controls 0 10-17-2006 10:07 PM
How to chang bgcolor of row when mouse selected a row? Charles Shao ASP .Net 1 04-18-2005 11:11 AM
How to add a new row to a datagrid with values of the selected row =?Utf-8?B?U3VyZXNo?= ASP .Net 1 11-22-2004 09:04 AM



Advertisments