03.11.2016 Views

Beginning ASP.NET 4.5 in CSharp and VB Opsylum

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

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

Us<strong>in</strong>g the Navigation Controls x 273<br />

FIGURE 7-10<br />

How It Works<br />

Just like the Menu control, the TreeView control can get its data from a SiteMapDataSource control,<br />

which <strong>in</strong> turn gets its <strong>in</strong>formation from the Web.sitemap file. By default, the TreeView shows plus<br />

<strong>and</strong> m<strong>in</strong>us signs to <strong>in</strong>dicate that items can be collapsed <strong>and</strong> exp<strong>and</strong>ed. For a site menu this may not<br />

make much sense, so by sett<strong>in</strong>g ShowExp<strong>and</strong>Collapse to False, you effectively hide the images. The<br />

TreeView enables you to set a number of style properties, <strong>in</strong>clud<strong>in</strong>g the NodeStyle, RootNodeStyle,<br />

<strong>and</strong> LevelStyles that <strong>in</strong>fluence the appearance of <strong>in</strong>dividual items <strong>in</strong> the tree. In this exercise, you<br />

used LevelStyles to apply a class called FirstLevelMenuItems that adds some room above each item<br />

at the top level, such as Home <strong>and</strong> Reviews.<br />

The code <strong>in</strong> the Code Beh<strong>in</strong>d of the master page looks at the current theme by <strong>in</strong>vestigat<strong>in</strong>g the Theme<br />

property of the Page. When DarkGrey is the current theme, the code hides the Menu <strong>and</strong> then displays<br />

the TreeView. In the Case Else / default block the reverse is true. This means that for the<br />

Monochrome theme <strong>and</strong> all future themes you may add, the TreeView is hidden <strong>and</strong> the Menu is used<br />

<strong>in</strong>stead as the navigation system.<br />

The TreeView still suffers from the same problems as the Menu control <strong>in</strong> previous versions of <strong>ASP</strong>.<strong>NET</strong><br />

<strong>in</strong> that it generates a lot of bloated HTML. Unfortunately, this control has no Render<strong>in</strong>gMode property,<br />

so if you’re us<strong>in</strong>g the TreeView you’re stuck with the table-based HTML.

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

Saved successfully!

Ooh no, something went wrong!