Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6918033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:48:26+00:00 2026-05-27T09:48:26+00:00

I found Bind ASP.NET Menu control to XML question helpful in find my problem.

  • 0

I found Bind ASP.NET Menu control to XML question helpful in find my problem. Now the problem I am facing is my menu looks like this (even the main menu as expanding menu attached to it. I want it to have a regular drop down. Can I achieve it?

enter image description here

My xmlfile is attached. I tried removing the root tag but than it is not a xml file and it breaks the code.

<?xml version="1.0" encoding="utf-8" ?>
<menu>
    <menuItem>
        <text>
            &lt;img align="middle" src="images/new.gif" width="32"
            height="16" /&gt; What's New? &lt;img align="middle"
            src="images/right.gif" width="16" height="16" /&gt;
        </text>
        <subMenu>
            <menuItem>
                <text>&amp;nbsp;&amp;nbsp;&amp;nbsp;New Articles</text>
                <url>/suboption1.1.html</url>
            </menuItem>
            <menuItem>
                <text>&amp;nbsp;&amp;nbsp;&amp;nbsp;New FAQs</text>
                <commandName>NewFAQ</commandName>
            </menuItem>
        </subMenu>
    </menuItem>
    <menuItem>
        <text>
            &lt;img align="middle" src="images/paw.gif" width="20"
            height="16" /&gt; Animal Facts &lt;img align="middle"
            src="images/right.gif" width="16" height="16" /&gt;
        </text>
        <url>/option2.html</url>
        <subMenu>
            <menuItem>
                <text>
                    <![CDATA[<img align="middle" src="images/paw.gif" 
              width="20" height="16" /> Animal Facts <img 
              align="middle" src="images/right.gif" width="16" 
              height="16" />]]>
                </text>
                <url>/suboption2.1.html</url>
                <subMenu>
                    <menuItem>
                        <text>Facts about Terriers</text>
                        <url>/suboption2.1.1</url>
                    </menuItem>
                    <menuItem>
                        <text>Facts about Beagles</text>
                        <url>/suboption2.1.2</url>
                    </menuItem>
                    <menuItem>
                        <text>Facts about Great Danes</text>
                        <url>/suboption2.1.3</url>
                    </menuItem>
                    <menuItem>
                        <text>Facts about Poodles</text>
                        <url>/suboption2.1.4</url>
                    </menuItem>
                </subMenu>
            </menuItem>
            <menuItem>
                <text>
                    &amp;nbsp;&amp;nbsp;&amp;nbsp;Facts About
                    Goats
                </text>
                <url>/suboption2.2.html</url>
            </menuItem>
            <menuItem>
                <text>
                    &amp;nbsp;&amp;nbsp;&amp;nbsp;Facts About
                    Snakes
                </text>
                <url>/suboption3.2.html</url>
            </menuItem>
        </subMenu>
    </menuItem>
    <menuItem>
        <text>
            &lt;img align="middle" src="images/email.gif" width="18"
            height="18" /&gt; Contact
        </text>
        <url>mailto:mitchell@4guysfromrolla.com</url>
    </menuItem>
</menu>

Adding Code

protected void Page_Load(object sender, EventArgs e)
{

    if (!Page.IsPostBack)
    {
        MainMenu.DataSource = GetSiteMapDataSource("firtmenu.xml");
        MainMenu.DataBind();
    }
}

private XmlDataSource GetSiteMapDataSource(string siteMapFileName)
{
    if (siteMapFileName != string.Empty)
    {
        XmlDataSource xmlSource = new XmlDataSource();
        xmlSource.DataFile = siteMapFileName;
        xmlSource.DataBind();
        return xmlSource;
    }
    else
    { return null; }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:48:26+00:00Added an answer on May 27, 2026 at 9:48 am

    Looks like it is not possible.

    Microsoft at this link says, the XML must have a root element and a proper structure of xml with menu,menuitem, and properties.

    The Menu class contains a DataSource property that can accept either a
    string path to an XML file or an XmlDocument instance that has already
    loaded the proper XML data. Specifically, the XML data must have a
    root element of with an arbitrary number of
    elements. Each element must have a element that
    specifies the text to display for the menu item, as well as optional
    and elements. If the menu item has a submenu, the
    element should contain a element, which, like the
    element, can have an arbitrary number of elements.

    Further …

    I found a similar thread on sitepoint, who asked the same question. The solution there is using XPATH to filter the result. In my example case, you will use

    XmlDataSource xmlSource = new XmlDataSource();              
    xmlSource.XPath = "/menu/menuItem"; // Notice XPAth filter in this line
    xmlSource.DataFile = siteMapFileName;
    

    It does filter the XML but it produces more problems. That is

    1. The root element is not shown (we need a heading for menu like Edit, File etc)
    2. All submenu are automatically expanded. If you hover over it, it will then expand the submenus.

    Looks like another poor implementation of Microsoft. It is rather not an implementation but just a bogus do this and that and then result, there is not result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i've found how to bind an asp:Menu to XML. i've found how to bind
I am trying to bind an ASP.NET GridView control to an string array and
I looking forward to find a suitable asp.net DataBound control (C#) to implement in
I've found it really handy that in MVC3 ASP.NET will map the incoming JSON
Newbie question. I’m writing an ASP.Net MVC app in VB.Net and have been using
This is a bit of a tough question to ask. I am using asp.net
I think I've found a bug in ASP.NET MVC controller's parameters population public JsonResult
Had a question about a implementation of bind function that I found on Mozilla's
Found some old code, circa VS 2003. Now I have just VS 2008 (SP1)
Found a piece of code today, that I find a little smelly... TMyObject.LoadFromFile(const filename:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.