Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Team Foundation Server Hosting
Search :       Advanced Search »
Home » ASP.NET 2.0/3.5 » Navigation controls in ASP.NET 2.0

Navigation controls in ASP.NET 2.0

In this article I am going to describe the Navigation controls. Navigation controls is the new feature of the ASP.NET 2.0. It provides the hierarchical structure of the data.

Author Rank :
Page Views : 5779
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

Introduction:

 

Site Navigation was one of major problems in website programming with ASP and ASP.NET early versions. ASP.NET 2.0 is coming with new features and controls to solve them. These features produced big enhancement in Navigation controls.

 

Navigation controls:

 

ASP.NET 2.0 has three new Navigation controls.

  • SiteMapPath
  • Menu
  • TreeView

Navigation controls are given below:

 

 

Figure 1: Group of Navigation controls.

 

SiteMapPath:

 

Use of this control is very simple. You can add this control to your page then view your page in browser. The SiteMapPath control displays the navigation path of the current page. The path acts as clickable links to previous pages.

 

The SiteMapPath control uses the web.sitemap file by default.

 

Code of SiteMapPath:

 

<asp:SiteMapPath ID="SiteMapPath1" runat="server"></asp:SiteMapPath>

 

SiteMapPath representation:

 

 

Figure 2: SiteMapPath control.

 

Example: In this Example you will see the source code of the SiteMapPath with some properties.

 

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>SiteMapPath</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:SiteMapPath ID="SiteMapPath1" runat="server" Font-Names="Verdana" Font-Size="0.8em" PathSeparator=" : " BackColor="#C0FFFF" BorderColor="Aqua" BorderStyle="Inset" Height="40px" Width="400px">

            <PathSeparatorStyle Font-Bold="True" ForeColor="#990000" />

            <CurrentNodeStyle ForeColor="#333333" />

            <NodeStyle Font-Bold="True" ForeColor="#990000" />

            <RootNodeStyle Font-Bold="True" ForeColor="#FF8000" />

        </asp:SiteMapPath>

    </div>

    </form>

</body>

</html>

 

Design view of the SiteMapPath:

 

 

Figure 3: SiteMapPage by using some properties.

 

Menu Control:

 

It was the very difficult task to maintain the menu of a large website and time consuming. It is used to display the Menus. You can use it as easy as other Navigation controls. Menu can be stored in a file to make it easier to maintain. This file is normally called web.sitemap, and is stored in the root directory of the web.

 

Example: In the following example you will see how the Menu controls create.

 

Step 1: Open the new website.

 

Step 2: Open ASP.NET Website.

 

Step 3: Drop the Menu control on the web form from the toolbox.

 

Step 4: Now right click on the Menu control and select edit menu item after that we edit menu items.

 

Step 5: Now right click on Menu control and select edit template then we add item template as static and dynamic item template as follows:

 

 

 

Figure 4: Edit item template.

 

Step 6: Write the code on menu itemClick().

 

Step 7: At last Debug the code.

 

Source code of the Menu Control:  

 

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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:Menu ID="Menu1" runat="server">

            <DynamicItemTemplateAudio songs<br />Video songs<br />

            </DynamicItemTemplate>

            <StaticItemTemplate>Songs<br /></StaticItemTemplate>

            <Items>

                <asp:MenuItem Text="Songs" Value="Songs">

                    <asp:MenuItem Text="New Item" Value="New Item"> </asp:MenuItem>

                </asp:MenuItem>

            </Items>

        </asp:Menu>

     </form>

</body>

</html>

 

Output of the above source code is as follows:

 

 

 

Now we click on songs then we get following output.

 

 

 

You can change the layout of this control with Orientation property.

  • Horizontal
  • Vertical

By default layout is vertical.

 

TreeView control:

 

A TreeView control displays a hierarchical list of items using lines to connect related items in a hierarchy. Each item consists of a label and an optional bitmap. Windows Explorer uses a TreeView control to display directories. You can use the TreeView control in any situation in which you need to display hierarchical data.

 

Source code of TreeView control is as follows:

 

<asp:TreeView ID="TreeView1" runat="server"> </asp:TreeView>

 

Example: We want to create the Employee's information in the hierarchical structure by using the TreeView control.

 

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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:TreeView ID="TreeView1" runat="server" BackColor="#FFFF80" BorderColor="DarkCyan"BorderStyle="Outset" ImageSet="BulletedList4"  ShowExpandCollapse="False" Width="192px">

            <ParentNodeStyle Font-Bold="False" />

            <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />

            <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px"VerticalPadding="0px" />

            <Nodes>

                <asp:TreeNode Text="Employee" Value="Employee">

                    <asp:TreeNode Text="Emp_Name" Value="Emp_Name">

                        <asp:TreeNode Text="First Name" Value="First Name">      </asp:TreeNode>

                        <asp:TreeNode Text="Last Name" Value="Last Name"> </asp:TreeNode>

                    </asp:TreeNode>

                        <asp:TreeNode Text="Emp_Address" Value="Emp_Address">

                        <asp:TreeNode Text="Local" Value="Local"></asp:TreeNode>

                        <asp:TreeNode Text="Permanent" Value="Permanent"> </asp:TreeNode>

                    </asp:TreeNode>

                    <asp:TreeNode Text="Emp_Contact no" Value="Emp_Contact no">

                    <asp:TreeNode Text="Home" Value="Home"></asp:TreeNode>

                    <asp:TreeNode Text="Office" Value="Office"></asp:TreeNode>

                    </asp:TreeNode>

                </asp:TreeNode>

            </Nodes>

            <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" HorizontalPadding="5px"NodeSpacing="0px" VerticalPadding="0px" />

        </asp:TreeView>

        </div>

    </form>

</body>

</html>

 

Design view of the above code is as  follows:

 

 

 

Figure 5: Structure of the TreeView control.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Purushottam Rathore

I am working as a Software Developer and has 4 years of experience on Microsoft Technology and having a Master Degree in Computer Application. I really like to work in the .NET platform. and working with ASP.NET 2.0/3.5, Web Services, WPF, WCF, Silverlight, AJAX, JavaScript, JQuery, Ado.net, MsAccess, SQL Server 2005/2008.

Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Team Foundation Server Hosting
Become a Sponsor
 Comments
Thanks by kyaw On August 19, 2009
Thanks for that
Reply | Email | Modify 
Re: Thanks by Purushottam On August 19, 2009
You r welcome
Reply | Email | Modify 
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.