Solved

Menu Control with XMLDataSource Issues - not horizontal and showing root node

Posted on 2013-01-28
2
569 Views
Last Modified: 2013-01-31
In VS2010 Express, the code below works, but it doesn't do two things I need it to do:

1)  Display the menu horizontally

2)  *Not* show the "Home" node (just show the menuitem entries in the XML horizontally)

Any help with this would be appreciated.

Thanks!

======page=======MenuTest01.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="MenuTest01.aspx.vb" Inherits="_Default" %>
<%@ Register TagPrefix="uc" TagName="Menu"
Src="~/MenuTestUC.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<uc:Menu ID="Menu1" runat="server" />
</form>
</body>
</html>

==========user control=========== MenuTestUC.ascx

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="MenuTestUC.ascx.vb" Inherits="WebUserControl" %>

<asp:Menu ID="Menu2" runat="server"
Orientation="Horizontal"
DisappearAfter="250"
MaximumDynamicDisplayLevels="2"
DataSourceID="XmlDataSource1">
<DataBindings>
<asp:MenuItemBinding DataMember="menuitem" NavigateUrlField="url"
TextField="Text" ValueField="Text" />
<asp:MenuItemBinding DataMember="submenuitem" NavigateUrlField="url"
TextField="Text" ValueField="Text" />
</DataBindings>
</asp:Menu>

<asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/MenuTest02.xml"></asp:XmlDataSource>

========= XML File ============MenuTest02.xml

<?xml version="1.0" encoding="utf-8" ?>
<Home>
<menuitem Text="Info" url="javascript:alert('info');"/>
<menuitem Text="Map" url="">
<submenuitem Text="Show" url="javascript: alert('showmap');"/>
<submenuitem Text="Home" url="javascript: alert('map home');"/>
</menuitem>
<menuitem Text="List" url="">
<submenuitem Text="Show" url="javascript: alert('show list');"/>
<submenuitem Text="Home" url="javascript: alert('list home');"/>
</menuitem>
</Home>
0
Comment
Question by:codequest
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 38832071
SiteMapDataSource is a good option if you can use it.

If you have to use XML file then, do a manual databinding instead of XMLDataSource.

e.g. Your menu:
<asp:Menu ID="Menu2" runat="server"
Orientation="Horizontal"
DisappearAfter="250"
MaximumDynamicDisplayLevels="3"
StaticDisplayLevels="1">
<DataBindings>
<asp:MenuItemBinding DataMember="menuitem" NavigateUrlField="url"
TextField="Text" ValueField="Text" />
<asp:MenuItemBinding DataMember="submenuitem" NavigateUrlField="url"
TextField="Text" ValueField="Text" />
</DataBindings>
</asp:Menu>

Open in new window


PageLoad code-behind of your UC:

If Not Page.IsPostBack Then
		Dim xmlPath As String = Server.MapPath("~/MenuTest02.xml")

		Dim xmlDS As New XmlDataSource()
		xmlDS.DataFile = xmlPath
		xmlDS.XPath = "Home/menuitem"
		Menu2.DataSource = xmlDS
		Menu2.DataBind()
		Menu2.Items(0).Text = ""
		Menu2.Items(0).Value = ""
		Menu2.Items(0).Selectable = False
End If

Open in new window


Check this.
0
 
LVL 2

Author Comment

by:codequest
ID: 38842269
Works slick!  Thanks.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question