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
- Drag WebGrid control to the WebForm.
- Bind WebGrid to AccessDataSource
control.
- Add OnRowContextMenu client-side event:
function WebGrid1_OnRowContextMenu(controlId, rowType, rowElement, menuObject)
{
menuObject.Items.GetNamedItem("mnuCopyRow").Hide();
return true;
}
|
To add a menu to context menu
- Drag WebGrid control to the WebForm.
- Bind WebGrid to AccessDataSource
control.
- Add OnRowContextMenu client-side event:
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);
}
|