Datagrid: get value from the row selected by user

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Datagrid: get value from the row selected by user

    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 Guest

  2. Similar Questions and Discussions

    1. new user question-no pixels selected pop-up
      Sorry if this is a double-post. I have a question. After making a selection within a layer,(not the background layer) why do I always get a pop-up...
    2. Newbie Question: User selected query
      I have a datagrid that is populated by a SQL query that is create by the user. Their is a DropDOwnList and a textbox. This gives them the WHERE...
    3. How to get user selected text?
      I'm trying to build an imput form in Flash MX 2004 Pro that has some very simple formatting tags for HTML. Is it possible to get the string of...
    4. Help for new user-no pixels selected pop-up
      Hi!Hope someone out there can help. I can find no answer to this is the help menu or in the book. Why, when trying to make a selection within a...
    5. user access to only selected pages
      Some time ago I set up an ASP application that used a login page which checked a username and password against a database to determine a users...
  3. #2

    Default Re: Datagrid: get value from the row selected by user

    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" <lifeng26@msn.com> wrote in message
    news:025601c3507a$8279fa10$a301280a@phx.gbl...
    > 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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139