?
Solved

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

Posted on 2013-01-28
2
Medium Priority
?
572 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticallā€¦
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called eeā€¦
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses

801 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