A Navigation System Comes Easily
As far as I know, before ASP .NET 2.0, there was not a system of website navigation controls to speak of. Different websites have different navigation styles and execution methods. Many advanced websites have database or XML files for content/navigation management; the others, especially the less dynamic ones, still have hard-coded navigation links. Some websites use topdown menus, some use sidebars; some use collapesable tree menus, some have bread-crumb style path information at the top of every web page. A lot of websites use a combination of all these methods.
Create a web.sitemap File
So, for a simple website that has the structure diagramed as the following:
the web.sitemap file would look like this:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/
SiteMap-File-1.0" >
<siteMapNode url="Default.aspx" title="Home"
description="Welcome to ASP .NET home">
<siteMapNode url="About.aspx" title="About Us" description="" >
<siteMapNode url="Histroy.aspx" title="History" description="" />
<siteMapNode url="Contact.aspx" title="Contact Us"
description="" />
</siteMapNode>
<siteMapNode url="Research.aspx" title="Research" description="" />
<siteMapNode url="" title="Publications" description="" >
<siteMapNode url="Current.aspx" title="History" description="" >
<siteMapNode url="Art.aspx" title="Arts and Culture"
description="" />
<siteMapNode url="Qol.aspx" title="Qaulity of Life"
description="" />
</siteMapNode>
<siteMapNode url="Archive.aspx" title="Contact Us"
description="" />
</siteMapNode>
</siteMapNode>
</siteMap>
With the SiteMap file created, you now are ready to use the three navigation controls.
How to use a TreeView Control
The TreeView control is already supported by ASP .NET 1.x and is most suitable to display a directory-like structure in Windows Explorer's style. It also has been widely used to display the hierarchical structure of XML files. Now, in ASP .NET 2.0, by binding with a web.sitemap file, a TreeView control would be perfect for a hierarchical menu that can be easily expanded and collapsed.
The ASPX code for a basic TreeView Control:
<asp:TreeView ID="TreeView1" runat="server"
DataSourceID="SiteMapDataSource1">
</asp:TreeView>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
The following is the screenshot of a TreeView menu using the XP File Explorer format.
<asp:TreeView ID="TreeView2" runat="server"
DataSourceID="SiteMapDataSource1"
ImageSet="XPFileExplorer" NodeIndent="15">
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
<SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False"
HorizontalPadding="0px" VerticalPadding="0px" />
<NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black"
HorizontalPadding="2px" NodeSpacing="0px" VerticalPadding="2px" />
</asp:TreeView >
How to Use a Menu Control
As with the TreeView control, you can apply a pre-existing format to the menu by selecting AutoFormat from the Menu control's smart tag menu. However, there is a very limited number of styles for the Menu control. You also may adjust the various style properties to customize the look and feel of a menu control. You can apply skins and themes to the Menu control. For more information, please read ASP.NET Menu Control Overview.
The following are the screenshot of a horizontal menu and its ASPX code:
<asp:Menu id="menu1" Orientation=Horizontal runat=server
DataSourceID="siteMapdataSource1" BackColor="#E3EAEB"
DynamicHorizontalOffset="2"
Font-Names="Verdana" Font-Size="0.8em" ForeColor="#666666"
StaticSubMenuIndent="10px">
<StaticMenuItemStyle HorizontalPadding="5px"
VerticalPadding="2px" />
<DynamicHoverStyle BackColor="#666666" ForeColor="White" />
<DynamicMenuStyle BackColor="#E3EAEB" />
<StaticSelectedStyle BackColor="#1C5E55" />
<DynamicSelectedStyle BackColor="#1C5E55" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticHoverStyle BackColor="#666666" ForeColor="White" />
>/asp:Menu>
How to Use a SiteMapPath Control
SiteMapPath is a great tool for users to quickly navigate back to the home page or to its higher-level section menu. Unlike TreeView and Menu Control, it does not use a SiteMapDataSource control and cannot be bound to other datasource. By default, it will be directly linked to the web.sitemap file for the each page's path information. However, you also may define a SiteMapProvider from which the SiteMapPath can retrieve data.
The ASPX code for a bareboned SiteMapPath control:
<asp:SiteMapPath ID="SiteMapPath1" runat="server">
</asp:SiteMapPath>
As you may have guessed, you may apply the few built-in formats for your SiteMapPath. As with all other controls, you can tinker with the many properties to set the appearance and styles of the SiteMapPath control. The SiteMapPath control supports different style settings for different types of nodes. Also, you may apply different skins and themes. In addition, you may design your own template to create a bread crumb path to suit your website's aesthetic needs.
The following is an example of a SiteMapPath using the professional autoformat.
<asp:SiteMapPath ID="SiteMapPath2" runat="server"
Font-Names="Verdana" Font-Size="0.8em"
PathSeparator=" : ">
<PathSeparatorStyle Font-Bold="True" ForeColor="#5D7B9D" />
<CurrentNodeStyle ForeColor="#333333" />
<NodeStyle Font-Bold="True" ForeColor="#7C6F57" />
<RootNodeStyle Font-Bold="True" ForeColor="#5D7B9D" />
</asp:SiteMapPath>
And, another example of a customized SiteMapPath using templates:
<asp:SiteMapPath ID="SiteMapPath3" runat="server">
<PathSeparatorTemplate>
<asp:Image ID="Image1" ImageUrl="~/images/arrow.gif"
runat="server" GenerateEmptyAlternateText="True" />
</PathSeparatorTemplate>
<RootNodeTemplate>
<img src="images/home.gif" border=0/>
<a href='<%# Eval("url") %>'><%# Eval("title") %></a>
</RootNodeTemplate>
<CurrentNodeTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("title") %>'>
</asp:Label>
</CurrentNodeTemplate>
</asp:SiteMapPath>
For more details about SiteMapPath control, please read ASP .NET quick start tutorials: SiteMapPath.
No comments:
Post a Comment