Datagrid wire SelectedIndexChanged event from linkbutton

Discussion in 'ASP .Net' started by Alex, Jun 8, 2005.

  1. Alex

    Alex Guest

    I have a datagrid with some dynamically generated columns containing
    linkButtons. How can I wire these events to fire the
    datagrid_SelectedIndexChanged?

    When clicking a template column defined in the IDE it works fine, the
    event fires. However, anything that I add in code does not fire this
    event?

    Any idea?

    Thanks

    Alex
     
    Alex, Jun 8, 2005
    #1
    1. Advertising

  2. I should note that generally speaking, adding controls to a datagrid like you
    are doing is not a good idea. Your code is generally much cleaner if you use
    template columns. I have not checked this code, but this should work:
    lkButton.Click += new EventHandler(DataGrid1_SelectedIndexChanged);

    where lkButton is your Button and DataGrid1_SelectedIndexChanged is your
    datagrid selected index changed method. It is important to note that the
    sender object will be a LinkButton and not a DataGrid row or anything like
    that.

    Hope that helps!

    Jason Lind

    "Alex" wrote:

    > I have a datagrid with some dynamically generated columns containing
    > linkButtons. How can I wire these events to fire the
    > datagrid_SelectedIndexChanged?
    >
    > When clicking a template column defined in the IDE it works fine, the
    > event fires. However, anything that I add in code does not fire this
    > event?
    >
    > Any idea?
    >
    > Thanks
    >
    > Alex
    >
    >
     
    =?Utf-8?B?SmFzb24gTCBMaW5k?=, Jun 8, 2005
    #2
    1. Advertising

  3. Alex

    Alex Guest

    Jason,

    Thanks for the reply. I am using a Template column in code to add the
    columns. How can I have the button inside my template column fire the
    datagrid SelectedIndexChanged?

    Thanks

    Alex
     
    Alex, Jun 8, 2005
    #3
    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. Chu
    Replies:
    2
    Views:
    921
    Winista
    Apr 10, 2006
  2. sonic
    Replies:
    0
    Views:
    524
    sonic
    Jun 26, 2006
  3. Linda

    Dynamically add linkbuttons and wire them to same event??

    Linda, Apr 28, 2004, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    144
    Robert Verderber
    Apr 28, 2004
  4. Russ
    Replies:
    2
    Views:
    461
  5. Eric
    Replies:
    1
    Views:
    200
    Steve Goodyear
    May 21, 2005
Loading...

Share This Page