I'm running into an issue with the ContextMenu where I need to select multiple nodes and use a context menu to apply an action to all those selected nodes. For example: I want to select 3 nodes for deletion, so I select the 3 nodes holding down CTRL, and then I right click on the node and the context menu appears. However, only the node that I right click is selected, the others are no longer selected. I found that when holding CTRL and selecting the first 2 nodes, then right-clicking the 3rd node while holding CTRL, it will select all 3 nodes.
I'm not doing autopostbacks, this is all contained client-side until they select an option (Add,Delete - took out that code here for space)
Javascript:
function ShowContextMenu(node, e) |
{ |
var menu = null; |
var item = null; |
var selectedNodes = null; |
menu = window["<%= RadMenu1.ClientID %>"]; |
menu.ContextMenuElementID = node.TreeView.ClientID; |
treeView = node.TreeView; |
selectedNodes = treeView.GetSelectedNodes(); |
var sNodes = "Selected Node Count: " + selectedNodes.length + "\r\n"; |
for(i=0;i<selectedNodes.length;i++) |
sNodes+= selectedNodes[i].Text + ", "; |
alert(sNodes); |
if (menu) |
{ |
menu.Show(e); |
e.cancelBubble = true; |
if (e.stopPropagation) |
{ |
e.stopPropagation(); |
} |
e.returnValue = false; |
if (e.preventDefault) |
{ |
e.preventDefault(); |
} |
} |
} |
function OnClick(sender, eventArgs) |
{ |
var menu = null; |
var selectedNodes = null; |
menu = window["<%= RadMenu1.ClientID %>"]; |
treeView = window[ menu.ContextMenuElementID ]; |
selectedNodes = treeView.GetSelectedNodes(); |
alert("Nodes Selected: " + selectedNodes.length); |
return true; |
} |
HTML:
<radT:RadTreeView ID="rtEntitlementPages" OnNodeDrop="rtEntitlementPages_NodeDrop" |
runat="server" DataTextField="Title" DataFieldID="PageId" DataFieldParentID="ParentPageId" |
DataValueField="PageId" DragAndDrop="true" DragAndDropBetweenNodes="true" MultipleSelect="true" |
BeforeClientContextMenu="ShowContextMenu"> |
</radT:RadTreeView> |
<radm:RadMenu ID="RadMenu1" runat="server" IsContext="True" OnClientItemClicking="OnClick" |
ContextMenuElementID="none" SkinID="TreeContextMenu" OnItemClick="RadMenu1_ItemClick" meta:resourcekey="RadMenu1Resource1"> |
<Items> |
<radm:RadMenuItem ID="RadMenuItem1" Text="Add" Value="Add" runat="server" meta:resourcekey="RadMenuItemAddResource" /> |
<radm:RadMenuItem ID="RadMenuItem3" Text="Delete" Value="Delete" runat="server" meta:resourcekey="RadMenuItemDeleteResource" /> |
</Items> |
</radm:RadMenu> |