DotNet Tutorials

V4 Dot Net Tutorials

Server Intellect Cloud Hosting

 Using TreeView for navigating with Master Pages in VB

This tutorial shows how to implement TreeView navigation system, which is very powerful yet easy to employ. VB version.

Especially for the larger sites, navigation can get a little messy at times. Fortunately, Visual Studio makes it easier for us to manage navigation and also construct a hierarchical navigation system that lets users transition freely between pages, especially when it comes to making changes to the web site.

Create an XML file containing the site hierarchy, page titles and URLs.

Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.

Web.sitemap:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
<siteMapNode title="Home" description="Home" url="~/Default.aspx" >
<siteMapNode title="Links" description="Links to Other Sites"
url="~/Links.aspx">
<siteMapNode title="Links 1"
description="Links to sites 1" url="~/Links1.aspx" />
<siteMapNode title="Links 2"
description="Links to sites 2" url="~/Links2.aspx" />
</siteMapNode>
<siteMapNode title="Games" description="Games you can play"
url="~/Games.aspx">
<siteMapNode title="Game 1" description="Game number 1"
url="~/Game1.aspx" />
<siteMapNode title="Game 2" description="Game number 2"
url="~/Game2.aspx" />
<siteMapNode title="Game 3" description="Game number 3"
url="~/Game3.aspx" />
</siteMapNode>
</siteMapNode>
</siteMap>

Add a SiteMapDataSource onto your Master Page. Default configuration is set to retrieve the data from Web.sitemap
Also add a TreeView control onto your Master Page, choosing the Data Source of the Site Map. To also add further navigation on each page, which displays where the current page is in the hierarcy, you can add a SiteMapPath control. Again, by default, the SiteMapPath uses the Web.sitemap file for its hierarchy data.

To add an expandable menu system onto the page also, add the Menu control and choose the Data Source.
The Master Page should look something like this:

We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.

<%@ Master Language="VB" AutoEventWireup="true" CodeFile="Navigation.master.vb" Inherits="Navigation" %>

<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
 <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
 <table style="width: 100%">
<tr>
<td style="width: 100px">
<asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1">
</asp:TreeView>
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1">
</asp:Menu>
</td>
<td style="width: 100px">
<asp:SiteMapPath ID="SiteMapPath1" runat="server">
</asp:SiteMapPath>
<br />
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>

All content pages should have the ContentPlaceHolders for the Master Page, and look something like this:

<%@ Page Language="VB" MasterPageFile="~/Navigation.master" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="Default" Title="Untitled Page" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<h1>Home</h1>
</asp:Content>


Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!



Looking for the C#.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!

Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!