Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ASP .NET 2.0 Beta Preview - B. Evjen.pdf
Скачиваний:
26
Добавлен:
24.05.2014
Размер:
15.33 Mб
Скачать

Site Navigation

The Menu1_MenuItemClick event includes the event delegate MenuEventArgs, which allows you to get at both the values of the child and parent elements selected. For this example, both are used and then populated into the Listbox control, as illustrated in Figure 5-27.

Figure 5-27

SiteMap Data Provider

A whole new series of data providers in the form of DataSource controls have been added to ASP.NET 2.0. One of these new DataSource controls now at your disposal, which we looked at earlier in the chapter, is the SiteMapDataSource control. This new DataSource control was developed to work with site maps and the controls that can bind to them.

Some controls don’t need a SiteMapDataSource control in order to bind to the application’s site map (which is typically stored in the web.sitemap file). Earlier in the chapter, you saw this in action when using the SiteMapPath control. This control was able to work with the web.sitemap file directly without the need for this new data provider.

Certain navigation controls, however, such as the TreeView control and the DropDownList control, require an intermediary SiteMapDataSource control to retrieve the site navigation information.

The SiteMapDataSource control is simple to use as demonstrated throughout this chapter. The SiteMapDataSource control in its simplest form is illustrated here:

<asp:SiteMapDataSource ID=”SiteMapDataSource1” Runat=”server” />

In this form, the SiteMapDataSource control simply grabs the info as a tree hierarchy (as consistently demonstrated so far). Be aware that a number of properties do change how the data is displayed in any control that binds to the data output.

SiteMapViewType

The SiteMapViewType property can take one of three available values: Tree, Flat, or Path. Changing this property’s value dramatically changes how the view of the site map data is represented in the control that binds to it. The following table describes each of these values.

165

Chapter 5

Value

Description

 

 

Tree

This is the default setting for the SiteMapViewType property. The value of

 

Tree assigns the hierarchical site map structure as it is presented in the site

 

map data file.

Flat

This value flattens the hierarchical structure of the data that is presented in

 

the site map data file so that no hierarchical structure is represented. This is

 

ideal setting for controls such as the DropDownList control.

Path

This value presents the navigation structure that shows the data as a hier-

 

archical structure from the current node to the root node (this is similar to

 

how it is presented in the SiteMapPath control).

 

 

StartingNodeType

The StartingNodeType property sets the depth where the SiteMapDataSource control starts retrieving node objects. It is based on the current node. For example, if you were looking at a page in the hierarchy that contained child nodes and you set the StartingNodeType to Root (which is the default), all the links for the entire hierarchy are displayed. However, if you set the StartingNodeType to Parent, only the parent node to the node being displayed and all the successive child nodes are displayed. Finally, if you set the StartingNodeType to Current, only the current node and any child nodes are shown in the hierarchy. This is demonstrated in Listing 5-25. For this example, use the site map from Listing 5-1 and create a page called Markets.aspx.

Listing 5-25: Changing the StartingNodeType values in Markets.aspx

<%@ Page Language=”VB” %>

<html xmlns=”http://www.w3.org/1999/xhtml” > <head runat=”server”>

<title>SiteMapDataSource</title>

</head>

<body>

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

<asp:SiteMapDataSource ID=”SiteMapDataSource1” Runat=”server” SiteMapViewType=”flat” StartingNodeType=”root” /> <asp:BulletedList ID=”BulletedList1” Runat=”server” DisplayMode=”HyperLink” DataSourceId=”SiteMapDataSource1” DataTextField=”Title” DataValueField=”Url” BulletStyle=”Circle” >

</asp:BulletedList>

</form>

</body>

</html>

For this page, the StartingNodeType is set to Root for the bulleted list of site links. This gives you the results illustrated in Figure 5-28.

166

Site Navigation

Figure 5-28

Now simply change the StartingNodeType to Parent, and you get the results illustrated in Figure 5-29.

Figure 5-29

And finally, set the StartingNodeType to Current, and you get the results shown in Figure 5-30.

167