datagrid command events not firing.

Discussion in 'ASP .Net' started by Peter Rilling, Apr 1, 2005.

  1. I have an interesting problem with a datagrid. It is the standard
    chicken-and-the-egg problem.

    I have this page with two datagrids. It essentially defines a parent-child
    relationship. The parent grid has a "edit" and "delete" columns. When the
    "edit" link button is clicked, I want the child grid to display some
    information related to the parent. Now the child grid also has some command
    buttons.

    My problem is that I cannot get the child grid to responded to the command
    events. The handlers are never invoked. Here is what I think the problem
    is. In order for the handlers to be invoked, the object model for the past
    must be the same on postback as was sent to the browser. That means that I
    have to initialize both grids their Init events so the command handlers will
    be invoked. The problem is, that when the parent grid's edit button is
    clicked, the Init fires as expected, but I do not know the ID for the item
    that was selected until the EditCommand handler is invoked. At this point,
    I could bind the grid and render the appropriate list items. But, if I do
    this, then if a command link is clicked on the child grid, the events do not
    fire since the grid was not built in the Init event.

    Any ideas at how I can solve this, assuming I made any sense?
     
    Peter Rilling, Apr 1, 2005
    #1
    1. Advertising

  2. Peter Rilling

    Ricky Smith Guest

    One of my co-workers just ran into this problem yesterday.

    First, make sure the sub that should fire has the 'handles' directive at
    the very right of the 'sub ...' line.

    For example:
    Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As
    System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
    DataGrid1.EditCommand


    Also .. be sure you are NOT binding the datagrid on post-backs.

    If you are running code (or calling a sub) in the page_load that does
    your data-binding, be sure to exclude it from postbacks. Like this:

    If Not IsPostBack Then
    .. DB CODE ..
    End If

    Hope that helps,
    Ricky

    Peter Rilling wrote:
    > I have an interesting problem with a datagrid. It is the standard
    > chicken-and-the-egg problem.
    >
    > I have this page with two datagrids. It essentially defines a parent-child
    > relationship. The parent grid has a "edit" and "delete" columns. When the
    > "edit" link button is clicked, I want the child grid to display some
    > information related to the parent. Now the child grid also has some command
    > buttons.
    >
    > My problem is that I cannot get the child grid to responded to the command
    > events. The handlers are never invoked. Here is what I think the problem
    > is. In order for the handlers to be invoked, the object model for the past
    > must be the same on postback as was sent to the browser. That means that I
    > have to initialize both grids their Init events so the command handlers will
    > be invoked. The problem is, that when the parent grid's edit button is
    > clicked, the Init fires as expected, but I do not know the ID for the item
    > that was selected until the EditCommand handler is invoked. At this point,
    > I could bind the grid and render the appropriate list items. But, if I do
    > this, then if a command link is clicked on the child grid, the events do not
    > fire since the grid was not built in the Init event.
    >
    > Any ideas at how I can solve this, assuming I made any sense?
    >
    >
     
    Ricky Smith, Apr 2, 2005
    #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. Rick
    Replies:
    1
    Views:
    477
    Richard Ryerson
    Feb 2, 2004
  2. Richard Ryerson
    Replies:
    0
    Views:
    2,633
    Richard Ryerson
    Jan 28, 2004
  3. Vikram Sinha
    Replies:
    0
    Views:
    463
    Vikram Sinha
    Apr 12, 2004
  4. Vikram Sinha
    Replies:
    0
    Views:
    508
    Vikram Sinha
    Apr 12, 2004
  5. SevDer
    Replies:
    2
    Views:
    1,306
    Walter Wang [MSFT]
    Nov 13, 2007
Loading...

Share This Page