DevPinoy.org
A Filipino Developers Community
ATTENTION:Take our Code Challenge for the month of October 2008 and win some great prize! Learn more about it here!

PageIndexChanged and SortCommand (Special ItemCommands)

This is to expound more on my previous post here regarding the behavior of datagrid's events.

I tried to refactor my codes one time on a webform with a grid on it.  Most of my ItemCommands has similar routine, obtain the PK id of the record from the grid’s datakey collection, instantiate the corresponding object and store it to Session.  I tried to remove the said routine outside my switch block:

[code language="C#"]
int pkID = datagrid1.DataKeys[e.Item.ItemIndex];
MyObject myObject = new MyObject(pkID);
switch(e.CommandName)
{
    ...
}
[/code]


Obviously the above handler for the grid’s ItemCommand event will raise an exception when the value of e.Item.ItemIndex is -1 which happens for special grid events like PageIndexChanged (CommandName = “Page”) and SortCommand (CommandName = “Sort”) which are special commands of the grid which triggers ItemCommand event first before their corresponding events.


Posted Aug 04 2005, 11:24 PM by jokiz
Filed under: , , ,

Comments

Atlanta ephedra lawyers. wrote Ephedra.
on 04-13-2008 6:32 AM

Herbal stimulant ephedra alternative. Hartford ephedra attorneys. Ephedra.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

Enter the numbers above:

Copyright DevPinoy 2005-2008
Powered by Community Server (Commercial Edition), by Telligent Systems