• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

asp:menu nodes not displaying properly with XML datasource

Hi,

I am trying to use an XML datasource and an ASP:menu control to display the menu.
I have managed to get the SubMenu items showing and linking properly but am unable to get the first level node to display properly. At the moment, with the code I have, it shows MenuItem MenuItem MenuItem MenuItem etc. When I hover over the MenuItem that has the SubMenus they actually display and link properly. I believe I have tried adjusting the depth settings correctly and any thing else I have thought of. The reason I am using the XML datasource and XML file is because I want to have images displayed instead of words, sitemapdatasource doesn't allow that.

code :

XML file -
<?xml version="1.0" encoding="utf-8" ?>
<Menu>  
  <MenuItem text="Home" url="~/default.aspx"></MenuItem>
  <MenuItem text="Computer Services" url="~/pages/comp.aspx"></MenuItem>
  <MenuItem text="Home Technologies" url="~/pages/theatre.aspx"></MenuItem>
  <MenuItem text="Car Technology" url="~/pages/caraudio.aspx"></MenuItem>
  <MenuItem text="Shop" url="~/pages/shop.aspx"></MenuItem>
  <MenuItem text="Contact Us">
    <SubMenuItem text="Send Us A Message" url="~/pages/contactus.aspx"></SubMenuItem>
    <SubMenuItem text="About Us" url="~/pages/about.aspx"></SubMenuItem>
  </MenuItem>
</Menu>

Open in new window

--------------------------------------------------------

.aspx -
  <asp:XmlDataSource ID="XMLDatasource" runat="server" DataFile="~/MenuList.xml" XPath="/Menu/MenuItem"></asp:XmlDataSource>
                    <asp:Menu ID="MXMLMenu" runat="server" DataSourceID="XMLDatasource" IncludeStyleBlock="False" Orientation="Horizontal" >
                        <DataBindings>
                            <asp:MenuItemBinding DataMember="MenuItem" TextField="text" ValueField="text" 
                            NavigateUrlField="url" />
                            <asp:MenuItemBinding DataMember="SubMenuItem" NavigateUrlField="url" TextField="text"
                            ValueField="text" Depth="1" />
                        </DataBindings>
                    </asp:Menu>

Open in new window


I just keep getting errors saying can not bind to "url" check my bindings. These look the same as any I have come across on the web.

Please Help!
0
Thwom
Asked:
Thwom
  • 2
1 Solution
 
hieloCommented:
Try XPath="/Menu" instead of XPath="/Menu/MenuItem"
0
 
ThwomAuthor Commented:
So, the solution is....

I had to have a url="" tag in the Contact Us menuitem! What a silly thing to have to do!
0
 
ThwomAuthor Commented:
Because I found the answer myself!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now