WebMenuBar can be created programmatically from server-side.
This topic will show you how to create WebMenuBar's structure programmatically in
server-side.
To create WebMenu programmatically in server-side
- Place the following code in Page_Load to create WebMenuBar's structure.
protected void Page_Load(object sender, EventArgs e)
{
// programmatically create command and items
MenuCommand cmdFile = new MenuCommand();
cmdFile.Name = "cmdFile";
cmdFile.AccessKey = "F";
cmdFile.Text = "File";
WebMenuItem itmNew = new WebMenuItem();
itmNew.Name = "itmNew";
itmNew.Text = "New";
WebMenuItem itmNewWindow = new WebMenuItem();
itmNewWindow.Name = "itmNewWindow";
itmNewWindow.Text = "New Window";
WebMenuItem itmNewTab = new WebMenuItem();
itmNewTab.Name = "itmNewTab";
itmNewTab.Text = "New Tab";
WebMenuItem separator = new WebMenuItem();
separator.Type = MenuItemType.Separator;
itmNew.Items.Add(itmNewTab);
cmdFile.Items.Add(itmNew);
cmdFile.Items.Add(new WebMenuItem("Open"));
cmdFile.Items.Add(new WebMenuItem("Save", "mnuSave", "../Images/Save.gif"));
cmdFile.Items.Add(separator);
cmdFile.Items.Add(new WebMenuItem("Exit", "mnuExit", "", "e"));
WebMenuBar1.Menus.Add(cmdFile);
}
|
- Run the project.