Solved

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

Posted on 2013-01-28
2
563 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
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now