Raising ItemCommand event from a DataGrid nested in a DataList

Discussion in 'ASP .Net' started by Matthew, May 18, 2004.

  1. Matthew

    Matthew Guest

    I have a DataGrid nested within a DataList. The DataGrid generates
    LinkButtons with specific CommandName values. I cannot figure out how
    to trap this event. I need to know which DataGrid LinkButton was
    selected.

    Thanks in advance.
     
    Matthew, May 18, 2004
    #1
    1. Advertising

  2. Matthew

    Vaibhav Guest

    give the link button on the datagrid a command name Like
    CommandName="DeleteClick" and then in the itemcommand event for the datagrid
    check for the command name like
    Private Sub dg_ItemCommand(ByVal source As Object, ByVal e As
    System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
    dgWires.ItemCommand

    If e.CommandName="DeleteClick" Then

    End If

    End Sub

    HTH

    "Matthew" <> wrote in message
    news:...
    > I have a DataGrid nested within a DataList. The DataGrid generates
    > LinkButtons with specific CommandName values. I cannot figure out how
    > to trap this event. I need to know which DataGrid LinkButton was
    > selected.
    >
    > Thanks in advance.
     
    Vaibhav, May 18, 2004
    #2
    1. Advertising

  3. Matthew

    Matthew Ward Guest

    The issue is that DataGrid is nested within a DataList.
    Therefore when you try to hook the event up (In InitializeComponent())
    using

    this.instancesGrid.ItemCommand += new
    DataGridCommandEventHandler(InstancesGrid_ItemCommand);

    you'll get a "Object reference not set to an instance of an object."
    error. That's because the grid doesn't exist yet. Therefore, I've
    tried to wait to hook up the event until the parent DataList
    ItemDataBound event.

    In the ItemDataBound event I had this code:
    ((DataGrid)e.Item.FindControl("instancesGrid")).ItemCommand += new
    DataGridCommandEventHandler(InstancesGrid_ItemCommand);

    Although that won't cause an error to be raised, it will not call the
    method I'm trying to call (InstancesGrid_ItemCommand). It does call
    some event because I can see the page postback, but I'm not sure what
    event that is.

    Thanks for your help.


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Matthew Ward, May 18, 2004
    #3
  4. Matthew

    ComputerGuru

    Joined:
    May 19, 2010
    Messages:
    1
    I know this is a 6-year old question, but I wanted to post a link to a blog article I wrote on how to solve this. It's very easy, and just requires the event to be attached at the ASPX level.

    Since I can't post the direct link to my blog because of velocity review's stupid 50-post limit, just do a search on Google for "geekteligence datagrid".
     
    ComputerGuru, May 19, 2010
    #4
  5. Matthew

    joseOZ

    Joined:
    May 26, 2010
    Messages:
    1
    tnx

    wow, i really DONT like registering en every forum i visit.
    BUT i decided to registar en this just to tell you TNX.

    this msg is for AAAAAALL administrators of forosdelweb.com
    that dont let you reply on a post of some months old.

    when i begin to read this page, i saw 2004 and i say THIS WILL
    NOT HELP, but when i saw you post 2010, i feel great.

    TNX for your info. this really helped.

    and i think 50post limit is stpid too
     
    joseOZ, May 26, 2010
    #5
    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. Jeremy
    Replies:
    0
    Views:
    395
    Jeremy
    Jul 2, 2004
  2. Mick
    Replies:
    0
    Views:
    396
  3. Nathan Sokalski
    Replies:
    1
    Views:
    495
    Teemu Keiski
    Sep 13, 2007
  4. Nathan Sokalski
    Replies:
    1
    Views:
    1,016
    Teemu Keiski
    Sep 13, 2007
  5. Nathan Sokalski
    Replies:
    1
    Views:
    228
    Teemu Keiski
    Sep 13, 2007
Loading...

Share This Page