15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

site navigation ❘ 1199<br />

You see an example XML site map later in this section.<br />

You can also use a TreeView control to display other structured data, but it really comes into its own with<br />

site maps, <strong>and</strong> gives you an alternative view of navigation information.<br />

The navigation web server controls are shown in the following table.<br />

ConTrol<br />

SiteMapPath<br />

Menu<br />

TreeView<br />

desCriPTion<br />

Displays breadcrumb-style information, allowing users to see where they are in the structure<br />

of a site <strong>and</strong> navigate to parent areas. You can supply various templates, such as NodeStyle<br />

<strong>and</strong> CurrentNodeStyle, to customize the appearance of the breadcrumb trail.<br />

Links to site map information via a SiteMapDataSource control, <strong>and</strong> enables a view of the<br />

complete site structure. The appearance of this control can be customized by templates.<br />

Allows the display of hierarchical data, such as a table of contents, in a tree structure. Tree<br />

nodes are stored in a Nodes property, with the selected node stored in SelectedNode.<br />

Several events allow for server-side processing of user interaction, including<br />

SelectedNodeChanged <strong>and</strong> TreeNodeCollapsed. This control is typically data-bound.<br />

adding a site map file<br />

To provide a site map XML fi le for your site, you can add a site map fi le ( .sitemap ) using the Website ➪<br />

Add New Item ... menu item. You link to site maps via providers. The default XML provider looks for a fi le<br />

called Web.sitemap in the root of your site, so unless you are going to use a different provider, you should<br />

accept the default fi lename supplied.<br />

A site map XML fi le contains a root element containing a single element, which<br />

in turn can contain any number of nested elements.<br />

Each < s iteMapNode > element uses the attributes shown in the following table.<br />

aTTribuTe<br />

Title<br />

url<br />

Roles<br />

description<br />

desCriPTion<br />

Page title, used as the text for links in site map displays<br />

Page location, used as the hyperlink location in site map displays<br />

The user roles that are allowed to see this site map entry in menus <strong>and</strong> so on<br />

Optional text used for tooltip pop-ups for site map displays<br />

When a site has a Web.sitemap fi le, adding a breadcrumb trail is as simple as putting the following code on<br />

your page:<br />

< asp:SiteMapPath ID="SiteMapPath1" Runat="server" / ><br />

This will use the default provider <strong>and</strong> the current URL location to format a list of links to parent pages.<br />

Adding a menu or tree view menu requires a SiteMapDataSource control, but again this can be very simple:<br />

< asp:SiteMapDataSource ID="SiteMapDataSource1" Runat="server" / ><br />

When using a custom provider, the only difference is that you can supply the provider ID via a<br />

SiteMapProvider attribute. You can also remove upper levels of the menu data (such as the root Home<br />

item) using StartingNodeOffset ; remove just the top - level link using ShowStartingNode= “ False “ ;<br />

start from the current location using StartFromCurrentNode= “ True “ ; <strong>and</strong> override the root node using<br />

StartingNodeUrl .<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!