Hi,
I'd like to be able to build my RowContextMenu at run-time based on the row being selected. Based on values in the selected row, I need to be able to modify my row context menu and JS calls to it.
How can I achieve this?
Thanks!
Hello Khaled,If you like you can set autopostback flags to true on RowSelection Change. This way everytime you go to the server you will be able to clear the items from the menu and add new one. What I would suggest to use only javascript and add all the necessary items in the context menu. Then on popping of the menu to disable or make invisible those items which should not be available like ContextMenu.getItems().getItem(0).set_visible(true) or ContextMenu.getItems().getItem(0).set_enabled(true) .Please let me know if those suggestions sound reasonably to you and if you face any issues implementing them.
I'm not sure I understand.Can you provide sample code?
I can set the following:
<ig:Selection CellClickAction="Cell" CellSelectType="None" ColumnSelectType="None" RowSelectType="Multiple"> <AutoPostBackFlags RowSelectionChanged="true" /> </ig:Selection>
But then, what event do I capture client side to do this?
Hello Khaled,I am attaching a sample implementing the scenario in which you load the items in the server. Please take a look at it and look me know if you have any further questions.
Hi Nikifor,
I tried to recreate your code in mine. I can step through the code and see the row context menu values being added on server side, and I see the client side code being hit. However, when I right click, I don't get the menu to pop up. I just get the browser's context menu.
One thing to note: eventArgs.get_item().get_row() This call gave me an error. There is no .get_row(). In fact when I step through with FireBug, I can't find that function after I type in get_item()
Any ideas what it may be?
Hello Khaled,Please take a look at the attached sample which is changing visibility of the items on the client.
Based on my project needs I have to implement a different solution. I had the WebDataMenu items created in the markup. During the MouseDown event, I would check certain conditions in my grid and hide menu items as needed.
Thanks.
Hello Khaled,Please let me know if you have any further questions regarding this issue.
Hello Khaled,I took a quick look at your project. Did you have the chance to look at my working attachment? Since you are modifying another control which is outside the grid no changes would be saved. In my sample I disabled the ajax of the grid and put both – menu and grid in an update panel to ensure that when I update the menu from the grid’s event the changes will be saved. Please take a look at the following page - http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel.aspx Another point is - no need to call Databind everytime the datarourse is set. The grid is calling automatically databind after you set datasource in page load. Databind should be called manually if you are setting a new datasource after the binding events have passed (render for example) or when you are making visual changes – for example hiding a column after the grid is bound. Your selection changed event was not triggered. Actually your selection was not persisted. The reason for this is that you call ClearDataSource to the grid which has to be called only when you are setting another datasource not the present one - http://help.infragistics.com/NetAdvantage/ASPNET/2012.2/CLR4.0?page=Infragistics4.Web.v12.2~Infragistics.Web.UI.GridControls.WebDataGrid~ClearDataSource.html . When you call this method you are clearing all the selection activation and other data which is persisted from our grid for the present datasource. After you remove this method the grid will start invoking the row selection changed server event in which you will be able to add the items in the menu. IF you follow my advice an add the grid and the menu in an update panel the menu will start to update its items when they are set from another control. Please note that the context menu is not showed if it does not have items at all and this is by desing. Regarding the row selection. Currently it is not possible to select a row because you have set cell click action to be cell not row so the property rowselectype – multiple is actually not working because you cant select a row.
I should also note that I need the right click the automatically select the row it happens on even if no row is currently selected.
Thank you.