Question

I have a MultiView and a Menu in my ASP.NET page - each menu item has a Value property which corresponds to the ViewIndex of the tab to show.

I will sometimes need to set the active view programatically, which works fine for the MultiView, but setting the Selected property of the Menu control is a bit more difficult. I could loop through each item til the value matches the view index I want to show, but this seems a bit hacky.

Any ideas?

Was it helpful?

Solution

I recommend using the MultiView's OnActiveViewChanged event to select the menu item.

protected void myMultiView_ActiveViewChanged(object sender, EventArgs e)
{
    int index = ((MultiView)sender).ActiveViewIndex;
    myMenu.FindItem(index.ToString()).Selected = true;
}

This way, whenever the view is changed (via SetActiveView(), or otherwise), the menu selection will remain synced. Note that you may also need to set the active view on the OnMenuItemClick event of the menu.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top