Which button was clicked and on which row?

Discussion in 'ASP .Net Datagrid Control' started by Yossi, Nov 17, 2006.

  1. Yossi

    Yossi Guest

    I have GridView with several text columns and 2 buttons. How do I determine
    which button on which row was clicked.

    I am able to detect a button clicked if I set the CommandText to "Select".
    All I have to do is write an event handler for the SelectedIndexChanged
    event and I get to know on which row the button was clicked. But how do I
    tell whether the first or second buttons where clicked?
     
    Yossi, Nov 17, 2006
    #1
    1. Advertising

  2. Yossi

    Yossi Guest

    I found the answer in the MSDN:

    To determine the index of the record that raises the command event, use the
    CommandArgument property of the event argument that is passed to the command
    event for the data-bound control. The ButtonField class automatically
    populates the CommandArgument property with the appropriate index value.

    Intellisense was not showing me a CommandArgument. That is why I got
    confused. Now all I have to do is set different CommandNames for each
    button in order to determine which one was clicked. Before, I set the
    CommandName of both buttons to Select and then I was handling the
    OnSelectedIndexChanged event. That was giving me the row, but not which
    button fired the select.


    "Yossi" <> wrote in message
    news:uczev%...
    >I have GridView with several text columns and 2 buttons. How do I
    >determine
    > which button on which row was clicked.
    >
    > I am able to detect a button clicked if I set the CommandText to "Select".
    > All I have to do is write an event handler for the SelectedIndexChanged
    > event and I get to know on which row the button was clicked. But how do I
    > tell whether the first or second buttons where clicked?
    >
    >
    >
     
    Yossi, Nov 17, 2006
    #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. Terry Olsen
    Replies:
    3
    Views:
    675
    Eliyahu Goldin
    Jul 12, 2005
  2. bthumber
    Replies:
    4
    Views:
    505
    bthumber
    Jun 25, 2010
  3. Jim Mitchell
    Replies:
    0
    Views:
    226
    Jim Mitchell
    Jul 12, 2003
  4. Replies:
    0
    Views:
    360
  5. iwasjoeking
    Replies:
    2
    Views:
    156
    iwasjoeking
    Jun 7, 2007
Loading...

Share This Page