Intersoft Support Center

Customize Context Menu

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

  1. Drag WebGrid control to the WebForm.
  2. Bind WebGrid to AccessDataSource control.
  3. 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

  1. Drag WebGrid control to the WebForm.
  2. Bind WebGrid to AccessDataSource control.
  3. 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);
    }
Previous Next