Skip to main content
Tab

MenuItemCollection.FindByText(String) Method

Returns an item object with the specified MenuItem.Text property value.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v23.2.dll

NuGet Package: DevExpress.Web

Declaration

public MenuItem FindByText(
    string text
)

Parameters

Name Type Description
text String

A String value representing the MenuItem.Text property value of the required item.

Returns

Type Description
MenuItem

A MenuItem object with a specific value of the MenuItem.Text property.

Remarks

Use this method to obtain an item specified by a display text assigned to its MenuItem.Text 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.

ASPxMenu_AddItems

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);
     }
} 
See Also