Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Horizontal Menu using XML instead of CSS

Status
Not open for further replies.

ASPNETnewbie

Programmer
May 9, 2006
93
US
I am trying to create a horizontal menu( drop down)such as the one on this page in ASP.NET using an XML file and I wanted to get examples or idea of how to go about dealing with this problem please. I want to be able to add or remove menu items from the menu by simply removing a line or two from the XML file. Please help with any ideas you may have

thanks

ASPNetNewbie
 
asp.net has built in functionality for this scenario with its menu control. you can use any type datasource for a menu and orient it both verically and horizontally.


Here's a full example of a horizontal menu using an xml file


This code is from the aspx page. It contains both the menu control and the refernece to the xml datasource which is using an xmlfile called XMLFile1.xml
Code:
    <asp:Menu ID="Menu1" runat="server" DataSourceID="XmlDataSource1" Orientation="Horizontal" StaticDisplayLevels="2">
            <DataBindings>
                <asp:MenuItemBinding DataMember="menu" NavigateUrlField="link" TextField="name" />
                <asp:MenuItemBinding DataMember="item" NavigateUrlField="link" TextField="name" />
            </DataBindings>
        </asp:Menu>
        <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XMLFile1.xml" XPath="/menu"></asp:XmlDataSource>



Here is the code for xmlfile1.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<menu name="Home Page" link ="[URL unfurl="true"]http://www.live.com">[/URL]
  <item name="Item 1" link="[URL unfurl="true"]http://www.live.com"[/URL] >
    <item name="SubItem 1" link="[URL unfurl="true"]http://www.live.com"[/URL] />
    <item name="SubItem 2" link="[URL unfurl="true"]http://www.live.com">[/URL]
      <item name="Sub SubItem 1" link="[URL unfurl="true"]http://www.live.com"[/URL] />
    </item>
  </item>
  <item name="Item 2" link="[URL unfurl="true"]http://www.live.com"[/URL] />
  <item name="Item 3" link="[URL unfurl="true"]http://www.live.com"[/URL] />
</menu>


Hope this helps

MCP, .Net Solutions Development <%_%>
 
Wow. Thanks, that there has saved me from hours of labouring. I just spent 4 hours trying to figure that out. Thanks a whole bunch!

ASPNETNEWBIE
 
Glad I could help!

Cheers

MCP, .Net Solutions Development <%_%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top