Welcome Guest Search | Active Topics | Sign In | Register

Grid Context Menu Options
Ramy
Posted: Thursday, May 5, 2011 6:32:29 AM
Rank: Member
Groups: Member

Joined: 3/8/2011
Posts: 19
I have a grid with a context menu. And all the options on the context menu calls server side code.
When the grid is populated, there is no selected item of grid, but as we move the mouse over the grid, the hover effect changes the color of the row, if we right click the context menu appears and then when we select a option, the code fires. But in my code I am checking the selected item, but since it is called from the item where mouse pointer is there, this item is not considered as selected item.
I require either of the one solution
1) On the server side to knoow which item has the mouse pointer.

2)Javasacript: to make the item selected from where context menu is called.



Thanks & Regards

eo_support
Posted: Thursday, May 5, 2011 10:13:42 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

The Grid exposes ContextItem and ContextCell property for this purpose. ContextItem contains the item on which the context menu was displayed.

Thanks!
Ramy
Posted: Sunday, May 8, 2011 1:10:33 AM
Rank: Member
Groups: Member

Joined: 3/8/2011
Posts: 19
I tried using the grid.contextitem but it was null.
It does not get anything unless the item is clicked and then right clicked.

Regards
eo_support
Posted: Sunday, May 8, 2011 8:04:31 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Your original post states "if we right click the context menu appears and then when we select an option, the code fires". We understand this as:

1. User right clicks a grid item, the context menu opens;
2. User clicks a context menu item. The context menu raises a server side ItemClick event;
3. Your server side ItemClick event is fired (this event is on the Menu control, not on the Grid control). At this point Grid.ContextItem contains the grid item that opens the context menu;

You can see how this works in our Grid -> Context Menu sample. You would check Grid1.ContextItem inside Menu1_ItemClick event handler (you need to click "Save" item in the context menu to raises server side Menu1_ItemClick event. Other menu items does not raises server event). You do NOT have to click an item in order to have Grid1.ContextItem. You can set a break point inside Menu1_ItemClick event to verify this.

In short, click changes SelectedItem. Right click changes ContextItem. These two are unrelated.

Hope this helps. Please feel free to let us know if you have any questions.

Thanks
Ramy
Posted: Tuesday, May 10, 2011 2:56:25 AM
Rank: Member
Groups: Member

Joined: 3/8/2011
Posts: 19
3. Your server side ItemClick event is fired (this event is on the Menu control, not on the Grid control). At this point Grid.ContextItem contains the grid item that opens the context menu;


I have checked the same. Grid.ContextItem is having a null value at this point.

I then click the item ad then right click the item, then grid.contextitem is having the item object.


eo_support
Posted: Tuesday, May 10, 2011 7:47:24 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Check a few things:

1. Make sure you use the latest version;

2. Make sure you do NOT clear or repopulate your Grid when the page posts back. The Grid automatically saves all items and restores them by default. ContextItem is passed back to the server from the client as an item index. So if you clear the Grid items during post back, then the Grid will not be able to translate item index back into an item. A common mistake is to rebind the Grid inside Page_Load without checking if Page.IsPostBack;

If those are not the problem, please try to isolate the problem into a test page and post the test page. Make sure the test page contains only code needed to reproduce the problem and runs independently. Once we have the test page, we will debug it here and see if we can find out why it works differently for you.

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.