Problem with DataGrid events

Discussion in 'ASP .Net Web Controls' started by Svetoslav Vasilev, Dec 4, 2003.

  1. Hello, i experienced some wiered behaviour from a
    DataGrid control. The instance of the control has both
    the ItemCommand and PageIndexChanged events assigned
    corresponding handler methods.It happened that the
    control fires the ItemCommand event handler when I click
    over a page number in order to change the current page. I
    find this behaviour strange since I used this approach
    with many other DataGrids and whenever a page number is
    clicked the PageIndexChanged event is fired and handled.
    I had to add a check for the CommandName of the command
    to be different than "Page" in order to have proper
    processing in the ItemCommand event handler.
    I would like to get some help on how to overcome this
    problem. The DataGrid is hosted in a user web control and
    the event handlers are dinamically assigned in the OnInit
    () method of that control.
    Thanks in advance.
    Svetoslav
     
    Svetoslav Vasilev, Dec 4, 2003
    #1
    1. Advertising

  2. Svetoslav Vasilev

    Sink Guest

    Hi,
    The problem is that the Pager is just another
    item as far as the OnItemCommand is concerned. The
    OnItemCommand is called becore the PageIndexChanged,
    but if your OnItemCommand happens to change pages,
    well your are gone, and probably somewhere unintended.
    The cure I use is to add the following line of
    code in the BEGINNING of the OnItemCommand handler,
    this is C#:

    if(e.Item.ItemType == ListItemType.Pager)
    return;

    The PageIndexCHange routine will then be called.
    Regards,
    Sink
    >-----Original Message-----
    >Hello, i experienced some wiered behaviour from a
    >DataGrid control. The instance of the control has both
    >the ItemCommand and PageIndexChanged events assigned
    >corresponding handler methods.It happened that the
    >control fires the ItemCommand event handler when I click
    >over a page number in order to change the current page. I
    >find this behaviour strange since I used this approach
    >with many other DataGrids and whenever a page number is
    >clicked the PageIndexChanged event is fired and handled.
    >I had to add a check for the CommandName of the command
    >to be different than "Page" in order to have proper
    >processing in the ItemCommand event handler.
    >I would like to get some help on how to overcome this
    >problem. The DataGrid is hosted in a user web control and
    >the event handlers are dinamically assigned in the OnInit
    >() method of that control.
    >Thanks in advance.
    >Svetoslav
    >.
    >
     
    Sink, Dec 4, 2003
    #2
    1. Advertising

  3. So this means that such behaviour is by design.Which also
    means that all the other places where I used DataGrid
    controls,the ItemCommand event handler is always executed
    before the PageIndexChanged handler. At least they should
    have explained this in the control documantation.
    Thanks for the reply.
    Svetoslav
     
    Svetoslav Vasilev, Dec 4, 2003
    #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. shiv
    Replies:
    0
    Views:
    482
  2. Alvin Bruney
    Replies:
    1
    Views:
    729
  3. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    order of events - dynamic checkbox events

    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Aug 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    568
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
    Aug 17, 2005
  4. newbye
    Replies:
    0
    Views:
    582
    newbye
    Jul 6, 2006
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    379
    Chris
    Aug 30, 2005
Loading...

Share This Page