| Main ASP .NET Tutorial Index |
Scott Mitchell June 2006 Download the ASPNET_Data_Tutorial_3_CS.exe sample code. Contents of Tutorial 3 (Visual C#)
Introduction Step 2: Creating a Site MapOne of the challenges of managing a website composed of more than a handful of pages is providing a straightforward way for visitors to navigate through the site. To begin with, the site's navigational structure must be defined. Next, this structure must be translated into navigable user interface elements, such as menus or breadcrumbs. Finally, this whole process needs to be maintained and updated as new pages are added to the site and existing ones removed. Prior to ASP.NET 2.0, developers were on their own for creating the site's navigational structure, maintaining it, and translating it into navigable user interface elements. With ASP.NET 2.0, however, developers can utilize the very flexible built in site navigation system. The ASP.NET 2.0 site navigation system provides a means for a developer to define a site map and to then access this information through a programmatic API. ASP.NET ships with a site map provider that expects site map data to be stored in an XML file formatted in a particular way. But, since the site navigation system is built on the provider model it can be extended to support alternative ways for serializing the site map information. Jeff Prosise's article, The SQL Site Map Provider You've Been Waiting For shows how to create a site map provider that stores the site map in a SQL Server database; another option is to create a site map provider based on the file system structure. For this tutorial, however, let's use the default
site map provider that ships with ASP.NET 2.0. To
create the site map, simply right-click on the
project name in the Solution Explorer, choose Add
New Item, and choose the Site Map option. Leave the
name as
Figure 9. Add a Site Map to Your Project The site map file is an XML file. Note that
Visual Studio provides IntelliSense for the site map
structure. The site map file must have the Define the site map to mimic the file system
structure. That is, add a Web.sitemap: <?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="Home">
<siteMapNode title="Basic Reporting" url="~/BasicReporting/Default.aspx" description="Basic Reporting Samples">
<siteMapNode url="~/BasicReporting/SimpleDisplay.aspx" title="Simple Display" description="Displays the complete contents of a database table." />
<siteMapNode url="~/BasicReporting/DeclarativeParams.aspx" title="Declarative Parameters" description="Displays a subset of the contents of a database table using parameters." />
<siteMapNode url="~/BasicReporting/ProgrammaticParams.aspx" title="Setting Parameter Values" description="Shows how to set parameter values programmatically." />
</siteMapNode>
<siteMapNode title="Filtering Reports" url="~/Filtering/Default.aspx" description="Samples of Reports that Support Filtering">
<siteMapNode url="~/Filtering/FilterByDropDownList.aspx" title="Filter by Drop-Down List" description="Filter results using a drop-down list." />
<siteMapNode url="~/Filtering/MasterDetailsDetails.aspx" title="Master-Details-Details" description="Filter results two levels down." />
<siteMapNode url="~/Filtering/DetailsBySelecting.aspx" title="Details of Selected Row" description="Show detail results for a selected item in a GridView." />
</siteMapNode>
<siteMapNode title="Customized Formatting" url="~/CustomFormatting/Default.aspx" description="Samples of Reports Whose Formats are Customized">
<siteMapNode url="~/CustomFormatting/CustomColors.aspx" title="Format Colors" description="Format the grid's colors based on the underlying data." />
<siteMapNode url="~/CustomFormatting/GridViewTemplateField.aspx" title="Custom Content in a GridView" description="Shows using the TemplateField to customize the contents of a field in a GridView." />
<siteMapNode url="~/CustomFormatting/DetailsViewTemplateField.aspx" title="Custom Content in a DetailsView" description="Shows using the TemplateField to customize the contents of a field in a DetailsView." />
<siteMapNode url="~/CustomFormatting/FormView.aspx" title="Custom Content in a FormView" description="Illustrates using a FormView for a highly customized view." />
<siteMapNode url="~/CustomFormatting/SummaryDataInFooter.aspx" title="Summary Data in Footer" description="Display summary data in the grid's footer." />
</siteMapNode>
</siteMapNode>
</siteMap>
The site map defines the website's navigational
structure, which is a hierarchy that describes the
various sections of the site. Each
Figure 10. The Site Map Represents a Hierarchical Navigational Structure (click image to enlarge)
ASP.NET exposes the site map's structure through
the .NET Framework's SiteMap
class!href(http://msdn2.microsoft.com/en-us/library/system.web.sitemap.aspx).
This class has a CurrentNode property, which returns
information about the section the user is currently
visiting; the RootNode property returns the root of
the site map (Home, in our site map). Both the
CurrentNode and RootNode properties return
SiteMapNode!href(http://msdn2.microsoft.com/en-us/library/system.web.sitemapnode.aspx)
instances, which have properties like ParentNode,
ChildNo
|
||||

