Datagrid: get value from the row selected by user

Discussion in 'ASP .Net' started by Northern, Jul 22, 2003.

  1. Northern

    Northern Guest

    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
     
    Northern, Jul 22, 2003
    #1
    1. Advertising

  2. Northern

    Greg Burns Guest

    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" <> wrote in message
    news:025601c3507a$8279fa10$...
    > 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
     
    Greg Burns, Jul 22, 2003
    #2
    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. =?Utf-8?B?U3VyZXNo?=
    Replies:
    1
    Views:
    483
    Saravana
    Nov 22, 2004
  2. Dan
    Replies:
    3
    Views:
    10,647
    Natheer sheriff
    May 30, 2009
  3. Dave
    Replies:
    1
    Views:
    172
    Saravana
    Jun 30, 2003
  4. mharness

    read keyfield value from selected row in datagrid

    mharness, Oct 11, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    123
    mharness
    Oct 11, 2004
  5. mharness
    Replies:
    2
    Views:
    184
    Bob Barrows [MVP]
    Oct 11, 2004
Loading...

Share This Page