Intersoft WebGrid Documentation
How-to: Add/Remove a menu in WebGrid's context menu
See Also Send comments on this topic.

Glossary Item Box

When you right click on the WebGrid, a Context Menu will appear. Sometimes you need to add/remove the menus in the WebGrid's Context Menu.

In this topic, you will learn how to Add/Remove WebGrid's context menu.

To remove "Copy this row" from context menu

 Add OnRowContextMenu client-side event:

JavaScript Copy ImageCopy Code
function WebGrid1_OnRowContextMenu(controlId, rowType, rowElement, menuObject) 
{    
   menuObject.Items.GetNamedItem("mnuCopyRow").Hide();    
   return true; 
}


To add a menu to context menu

Add OnRowContextMenu client-side event:

JavaScript Copy ImageCopy Code
function WebGrid1_OnRowContextMenu(controlId, rowType, rowElement, menuObject) 
{    
   var separator = new WebMenuItem();    
   separator.Type = "Separator";       
   separator.Name = "MySeparator";          

   var menuItem = new WebMenuItem();    
   menuItem.Text = "View Row's KeyValue";    
   menuItem.Name = "MyMenu";    
   menuItem.OnClick = "RowKeyValue";          

   // Add Menu Separator and Menu Item    
   menuObject.Items.Add(separator);    
   menuObject.Items.Add(menuItem);
}

function RowKeyValue() 
{    
   var grid = ISGetObject("WebGrid1");    
   var key = grid.GetSelectedObject().GetRowObject().KeyValue;
   alert(key);
}

See Also

©2012 Intersoft Solutions Corp. All Rights Reserved.