Server Intellect
 
Home   Asp.Net Tutorials   What's New   Newsletter   More Resources
 
 
  Categories
Advanced Technologies
AJAX
Internet Browsers
Controls
Database
Email
Error Handling
File
Graphics
Website Navigation
Network
Performance
User Interface and Themes
Validation
Visual Web Developer
Web Services
XML
Suggest Tutorial


Navigator: Home - Tutorials - Website Navigation - Using TreeView for navigating with Master Pages in VB
Using TreeView for navigating with Master Pages in VB


ASP.NET Website Navigation Tutorial

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.

Download the Full Working Version of this Project written with Visual Studio.NET VB 2005 Here!

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

Looking for more ASP.NET Tutorials? Click Here!

Create an XML file containing the site hierarchy, page titles and URLs.
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:

<%@ 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>

Download the Full Working Version of this Project written with Visual Studio.NET VB 2005 Here!

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

Looking for more ASP.NET Tutorials? Click Here!







 
  Developer Resources







Server Intellect Rocks