ASPxMenuBase.SelectedItem Property
Gets or sets the selected menu item within a menu control.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v24.2.dll
Declaration
Property Value
Type | Description |
---|---|
MenuItem | A MenuItem object representing the selected item. |
Remarks
If the ASPxMenuBase.AllowSelectItem property is set to true
, end users are allowed to select menu items via mouse clicks. A menu control (which can be either the ASPxMenu or ASPxPopupMenu) also provides the ability to select its items via code. You can use the SelectedItem property on the server side for this purpose.
Note that only one menu item can be selected within a menu control at the same time, and this item is displayed selected only if the menu’s ASPxMenuBase.ItemLinkMode property is set to the ItemLinkMode.ContentBounds value.
If none of the items is selected within a menu control or selecting is prohibited, the SelectedItem property returns null (Nothing in Visual Basic).
The selected state of an individual menu item can be specified by its MenuItem.Selected property.
Example
The code sample below demonstrates how to populate an ASPxMenu control with items manually, in unbound mode. The image below shows the result.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
CreateMenu();
}
}
//Create Menu initial structure.
void CreateMenu() {
string[] Items = { "Home", "News", "Products", "Client Center" };
foreach (string ItemText in Items) {
MyMenu.Items.Add(ItemText);
}
MyMenu.Items.FindByText("News").Items.Add("Subscriptions");
MenuItem[] ProductsItems = {
new MenuItem("Downloads"),
new MenuItem("Support"),
new MenuItem("Order")
};
MyMenu.Items.FindByText("Products").Items.Add(ProductsItems);
}
//Add a new item
protected void btnAddItem_Click(object sender, EventArgs e) {
if ((MyMenu.SelectedItem != null) && (tbItemName.Text != "")) {
MyMenu.SelectedItem.Items.Add(tbItemName.Text);
}
}