There are two general approaches: server-side and client-side. In both cases, firstly, it's necessary to create all of the menu items using the ASPxGridView.FillContextMenuItems event. After that, some of menu items can be made invisible or disabled depending on certain conditions.
Server-side solution.
Handle the ASPxGridView.ContextMenuItemVisibility event and use its e.SetVisible and e.SetEnabled methods to show/hide or enable/disable items respectively.
Note that these methods have overloaded versions that allow one to change visibility or enabled state for a specific row or a specific column.
It's very important to set the ASPxGridViewBehaviorSettings.ProcessSelectionChangedOnServer property value to true. In this case, each time a row is selected or unselected, a callback will be sent to the server and context menu items will be recalculated. If this property value is set to false, the context menu won't be updated after selecting or unselecting a row on the client side.
So, this approach requires callbacks to be sent to the server each time the end-user selects or unselects a row. This is why the server-side approach is less preferable than the client-side one.
Client-side solution.
Since the grid's data isn't available on the client side, to hide or disable rows depending on certain data, we need to analyze that data on the server side to determine whether or not a row must be made invisible or disabled and pass this information to the client side. A good way to achieve this is to create a List<bool> object that would contain required information and pass it to the client side as a custom JavaScript property.
Then handle the ASPxClientGridView.ContextMenu event and use the e.menu property to get the ASPxClientPopupMenu object that represents the context menu. After that, you can use the e.menu.GetItemByName method to get a menu item and then the SetEnabled and SetVisible methods to enable/disable or show/hide items respectively.
In the example, there are three items in the context menu. The first of them is always visible and enabled; the second is always enabled, but visible only for selected rows; and the third one is always visible, but enabled only for selected rows that have a corresponding "Discontinued" field value set to "true". There are two pages in the example that demonstrate both the client-side and the server-side approaches.
Question Comments
Added By: Steve Mol at: 6/19/2014 11:46:56 PM
For a hybrid approach, you can set the ASPxGridViewBehaviorSettings.ProcessSelectionChangedOnServer property value to false. Then, handle the event on the Client-side. If it is determined in the Client-side that the circumstances require the server to handle the event, set e.processOnServer to true. In this way, anything that can be handled on the Client-side will be and no callback will occur. But if the server is needed, the callback can be forced.
On the other hand, you can set the ASPxGridViewBehaviorSettings.ProcessSelectionChangedOnServer property value to true. The Client-side event will still be called, and you can set e.processOnServer to false to cancel the callback.
Either approach should reduce the callback occurrences to only what is required.