WebPartsDisplayMode ASP.Net
<p>I am trying to add the modes existing in webpartmanager to a menu control but I keep on getting an error message whenever I attempt to iterate through the DisplayModes..</p>

<p>Here is a snippet of the code: 
 if (!IsPostBack)
        {
            MenuItem root = new MenuItem("Select Mode");
            foreach(WebPartDisplayMode mode in WebPartManager1.DisplayMode)
            {
                if (mode.IsEnabled(WebPartManager1))
                {
                    root.ChildItems.Add(new MenuItem(mode.Name));</p>

<pre><code>            }

        }
        ModesMenu.Items.Add(root);
    }
</code></pre>

<p>Can you advise please?
Thanks...</p>
