Problem with DataGrid events

  • Thread starter Svetoslav Vasilev
  • Start date
S

Svetoslav Vasilev

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
 
S

Sink

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
 
S

Svetoslav Vasilev

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top