ASP.NET 4.0 : Data Source Components (part 9) - The SiteMapDataSource Class - Displaying Site Map Information

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

6. The SiteMapDataSource Class

Site maps are a common feature of cutting-edge Web sites. A site map is the graph that represents all the pages and directories found in a Web site. Site map information is used to show users the logical coordinates of the page they are visiting, allow users to access site locations dynamically, and render all the navigation information in a graphical fashion (as shown in Figure 3).

Figure 3. The graphical layout that the MSDN Magazine Web site uses to represent the location of a page in the site hierarchy.

ASP.NET contains a rich navigation infrastructure that allows developers to specify the site structure. I cover site navigation in detail in Programming Microsoft ASP.NET 2.0 Applications: Advanced Topics (Microsoft Press, 2006). For now, it suffices to say that the site map is a hierarchical piece of information that can be used as input for a hierarchical data source control such as SiteMapDataSource. The output of SiteMapDataSource can be bound to hierarchical data-bound controls such as Menu.

6.1 Displaying Site Map Information

The sitemap information can appear in many ways, the simplest of which is to place an XML file named web.sitemap in the root of the application. To give you the essence of site maps and site map data sources, let’s briefly review a few usage scenarios. Suppose you’re writing a Web site and your client asks for a sequence of hyperlinks that indicates the location of the page in the site map. In ASP.NET 1.x, you have to create your own infrastructure to hold site map information and render the page location. (Typically, you would use a configuration file and a user control.) Starting with version 2.0, ASP.NET provides richer support for site maps. You start by creating a configuration file named web.sitemap in the root of the Web application. The file describes the relationship between pages on the site. Your next step depends on the expected output.

If the common representation shown in Figure 3 (a sequence of hyperlinks with a separator) is what you need, add a SiteMapPath control to the page. This control retrieves the site map and produces the necessary HTML markup. In this simple case, there is no need to resort to a site map data source control. If you need to build a more complex hierarchical layout—for example, a tree-based representation—you need the SiteMapDataSource control.

The SiteMapDataSource control pumps site map information to a hierarchical data-bound control (for example, the new TreeView control) so that it can display the site’s structure. Here’s a quick example:

<%@ Page Language="C#" %>
<form runat="server">
<asp:SiteMapDataSource runat="server" ID="MySiteMapSource" />
<asp:TreeView runat="server" DataSourceId="MySiteMapSource" />

Figure 4 shows the final output as it appears to the end user.

Figure 4. The site map information rendered through a TreeView control.

The site map information might look like the following:

<siteMapNode title="Home" url="default.aspx" >
<siteMapNode title="Acknowledgements" url="ack.aspx"/>
<siteMapNode title="References" url="ref.aspx" />
<siteMapNode title="Samples">
<siteMapNode title="Part 1">
<siteMapNode title="Chapter 1" />
<siteMapNode title="Chapter 2" />
<siteMapNode title="Chapter 3">
<siteMapNode title="Dynamic Controls"
url=".../dynctls.aspx" />
<siteMapNode title="ViewState"
url=".../viewstate.aspx" />
<siteMapNode title="Chapter 4" />
<siteMapNode title="Part 2">
<siteMapNode title="Chapter 9">
<siteMapNode title="Site map"
url=".../sitemapinfo.aspx" />
<siteMapNode title="Part 3"
url="samples.aspx?partid=3" />

Note that the url attribute is optional. If the attribute is not defined, the node is intended to be an inert container and won’t be made clickable.


As mentioned, with version 2.0 ASP.NET introduces a new type of data-bound control that was completely unsupported in previous versions—the hierarchical data-bound control. A new base class is defined to provide a minimum set of capabilities—HierarchicalDataBoundControl. The TreeView and Menu controls fall into this category.

  •  ASP.NET 4.0 : Data Source Components (part 8) - The LinqDataSource Class -Lazy Loading and Prefetch, Updating Data
  •  ASP.NET 4.0 : Data Source Components (part 7) - The LinqDataSource Class - Selecting, Sorting, and Filtering Data
  •  ASP.NET 4.0 : Data Source Components (part 6) - The LinqDataSource Class - The Goal of LinqDataSource , Programming Interface of the LinqDataSource Control
  •  ASP.NET 4.0 : Data Source Components (part 5) - The ObjectDataSource Control - Setting Up for Paging , Updating and Deleting Data
  •  ASP.NET 4.0 : Data Source Components (part 4) - The ObjectDataSource Control - Using Parameters, Caching Data and Object Instances
  •  ASP.NET 4.0 : Data Source Components (part 3) - The ObjectDataSource Control - Implementing Data Retrieval
  •  ASP.NET 4.0 : Data Source Components (part 2) - The SqlDataSource Control
  •  ASP.NET 4.0 : Data Source Components (part 1) - Internals of Data Source Controls
  •  ASP.NET 4.0 : Data-Binding Expressions (part 2) - Other Data-Binding Methods
  •  ASP.NET 4.0 : Data-Binding Expressions (part 1) - Simple Data Binding
    Top 10
    Free Mobile And Desktop Apps For Accessing Restricted Websites
    MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
    TOYOTA CAMRY 2; 2.5 : Camry now more comely
    KIA SORENTO 2.2CRDi : Fuel-sipping slugger
    How To Setup, Password Protect & Encrypt Wireless Internet Connection
    Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
    Backup & Restore Game Progress From Any Game With SaveGameProgress
    Generate A Facebook Timeline Cover Using A Free App
    New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
    SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
    - Messages forwarded by Outlook rule go nowhere
    - Create and Deploy Windows 7 Image
    - How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
    - Creating and using an unencrypted cookie in ASP.NET
    - Directories
    - Poor Performance on Sharepoint 2010 Server
    - SBS 2008 ~ The e-mail alias already exists...
    - Public to Private IP - DNS Changes
    - Send Email from Winform application
    - How to create a .mdb file from ms sql server database.......
    programming4us programming4us