In this topic, you will learn how to add a SubMenu in WebGrid's context menu.
To add SubMenu in WebGrid's context menu
Add OnRowContextMenu client side event like following:
JavaScript | Copy Code |
function WebGrid1_OnRowContextMenu(controlId, rowType, rowElement, menuObject) { var menuItem1 = new WebMenuItem(); menuItem1.Text = "Menu1"; menuItem1.Name = "MyMenu1"; menuItem1.OnClick = "OnClick"; var menuItem2 = new WebMenuItem(); menuItem2.Text = "Menu2"; menuItem2.Name = "MyMenu2"; menuItem2.OnClick = "OnClick"; var menuItem3 = new WebMenuItem(); menuItem3.Text = "Menu3"; menuItem3.Name = "MyMenu3"; menuItem3.OnClick = "OnClick"; var separator = new WebMenuItem(); separator.Type = "Separator" separator.Name = "MySeparator" var subItem1 = new WebMenuItem(); subItem1.Text = "Sub 1"; subItem1.Text = "MySub1"; subItem1.OnClick = "OnClick"; var subItem2 = new WebMenuItem(); subItem2.Text = "Sub 2"; subItem2.Text = "MySub2"; subItem1.OnClick = "OnClick"; menuItem1.Items.Add(subItem1); menuItem1.Items.Add(subItem2); menuObject.Items.Add(menuItem1); menuObject.Items.Add(menuItem2); menuObject.Items.Add(separator); menuObject.Items.Add(menuItem3); return true; } function OnClick(menuItem) { // execute function for selected menuItem alert("Menu.Name : " + menuItem.Name + "\n" + "Menu.Text = " + menuItem.Text); return true; } |