
- •Contents
- •Introduction
- •Acknowledgments
- •The Goals of ASP.NET 2.0
- •Developer productivity
- •Administration and management
- •Performance and scalability
- •Device-specific code generation
- •Additional New Features of ASP.NET 2.0
- •New developer infrastructures
- •New compilation system
- •Additions to the page framework
- •New objects for accessing data
- •New server controls
- •A New IDE for Building ASP.NET 2.0 Pages
- •The Document Window
- •Views in the Document Window
- •The tag navigator
- •Page tabs
- •Code change status notifications
- •Error notifications and assistance
- •The Toolbox
- •The Solution Explorer
- •Lost Windows
- •Other Common Visual Studio Activities
- •Creating new projects
- •Making references to other objects
- •Using smart tags
- •Saving and importing Visual Studio settings
- •Application Location Options
- •Built-in Web server
- •Web site requiring FrontPage Extensions
- •The ASP.NET Page Structure Options
- •Inline coding
- •New code-behind model
- •New Page Directives
- •New attributes
- •New directives
- •New Page Events
- •Cross-Page Posting
- •New Application Folders
- •\Code folder
- •\Themes folder
- •\Resources folder
- •Compilation
- •The New Data Source Controls
- •The SqlDataSource and GridView Controls
- •Reading data
- •Applying paging in the GridView
- •Sorting rows in the GridView control
- •Defining bound columns in the GridView control
- •Enabling the editing of rows in the GridView control
- •Deleting data from the GridView
- •Dealing with other column types in the GridView
- •Selecting which fields to display in the DetailsView control
- •Using the GridView and DetailsView together
- •Updating, inserting, and deleting rows
- •XmlDataSource Control
- •ObjectDataSource Control
- •SiteMapDataSource Control
- •DataSetDataSource Control
- •Visual Studio 2005
- •Connection Strings
- •Site Maps
- •The PathSeparator property
- •The PathDirection property
- •The ParentLevelsDisplayed property
- •The ShowToolTips property
- •Examining the parts of the TreeView control
- •Binding the TreeView control to an XML file
- •Selecting multiple options in a TreeView
- •Specifying custom icons in the TreeView control
- •Specifying lines used to connect nodes
- •Working with the TreeView control programmatically
- •Applying different styles to the Menu control
- •Menu Events
- •Binding the Menu control to an XML file
- •SiteMap Data Provider
- •SiteMapViewType
- •StartingNodeType
- •SiteMap API
- •Why Do You Need Master Pages?
- •The Basics of Master Pages
- •Coding a Master Page
- •Coding a Content Page
- •Mixing page types and languages
- •Specifying which master page to use
- •Working with the page title
- •Working with controls and properties from the master page
- •Nesting Master Pages
- •Container-Specific Master Pages
- •Event Ordering
- •Caching with Master Pages
- •Using ASP.NET 2.0 Packaged Themes
- •Applying a theme to a single ASP.NET page
- •Applying a theme to an entire application
- •Applying a theme to all applications on a server
- •Removing themes from server controls
- •Removing themes from Web pages
- •Removing themes from applications
- •Creating Your Own Themes
- •Creating the proper folder structure
- •Creating a skin
- •Including CSS files in your themes
- •Having your themes include images
- •Defining Multiple Skin Options
- •Programmatically Working with Themes
- •Themes and Custom Controls
- •Authentication
- •Authorization
- •ASP.NET 2.0 Authentication
- •Setting up your Web site for membership
- •Adding users
- •Asking for credentials
- •Working with authenticated users
- •Showing the number of users online
- •Dealing with passwords
- •ASP.NET 2.0 Authorization
- •Using the LoginView server control
- •Setting up your Web site for role management
- •Adding and retrieving application roles
- •Deleting roles
- •Adding users to roles
- •Getting all the users of a particular role
- •Getting all the roles of a particular user
- •Removing users from roles
- •Checking users in roles
- •Using the Web Site Administration Tool
- •The Personalization Model
- •Adding a simple personalization property
- •Using personalization properties
- •Adding a group of personalization properties
- •Using grouped personalization properties
- •Defining types for personalization properties
- •Using custom types
- •Providing default values
- •Making personalization properties read-only
- •Anonymous Personalization
- •Enabling anonymous identification of the end user
- •Working with anonymous identification events
- •Anonymous options for personalization properties
- •Migrating Anonymous Users
- •Personalization Providers
- •Working with the Access personalization provider
- •Working with the SQL Server personalization provider
- •Using multiple providers
- •Building Dynamic and Modular Web Sites
- •Introducing the WebPartManager control
- •Working with zone layouts
- •Understanding the WebPartZone control
- •Explaining the WebPartPageMenu control
- •Modifying zones
- •Caching in ASP.NET 1.0/1.1
- •Output caching
- •Partial page caching
- •Data caching using the Cache object
- •Cache dependencies
- •ASP.NET 2.0 unseals the CacheDependency class
- •Enabling databases for SQL Server cache invalidation
- •Enabling tables for SQL Server cache invalidation
- •Looking at SQL Server
- •Looking at the tables that are enabled
- •Disabling a table for SQL Server cache invalidation
- •Disabling a database for SQL Server cache invalidation
- •Configuring your ASP.NET Application
- •Adding more than one table to a page
- •Attaching SQL Server cache dependencies to the Request object
- •Attaching SQL Server cache dependencies to the Cache object
- •Customizing the side navigation
- •Examining the AllowReturn attribute
- •Working with the StepType attribute
- •Adding a header to the Wizard control
- •Utilizing Wizard control events
- •Working with images from disk
- •Resizing images
- •Displaying images from streams
- •The MMC ASP.NET Snap-In
- •General
- •Custom Errors
- •Authorization
- •Authentication
- •Application
- •State Management
- •Advanced
- •ASP.NET Web Site Administration Tool
- •Home
- •Security
- •Profile
- •Application
- •Provider
- •Managing the Site Counter System
- •Generics
- •Iterators
- •Anonymous Methods
- •Operator Overloading
- •Visual Basic XML Documentation
- •New Visual Basic Keywords
- •Continue
- •Using
- •Global
- •Index

Site Navigation
In this example, you first set the ShowTextBoxes property to Leaf, meaning that you are only interested in having check boxes appear next to items in the TreeView control which do not contain any child nodes. The only items with check boxes next to them should be the last item that can be expanded in
the hierarchical list.
After this property is set, you then work with the items that are selected by the end user in the Button1_Click event. The first thing you should check is whether any selection at all was made:
If TreeView1.CheckedNodes.Count > 0 Then
...
End If
In this case, the number of checked nodes on the postback needs to be greater than zero, meaning that at least one was selected. If so, you can execute the code within the If statement. The If statement then proceeds to populate the Label control that is on the page. To populate the Label control with data from the selected nodes, you use a For Each statement, as shown in the following:
For Each node As TreeNode In TreeView1.CheckedNodes
...
Next
This creates an instance of a TreeNode object and checks each TreeNode object within the TreeView1 collection of checked nodes.
For each node that is checked, you grab the nodes Text value and the Text value of this node’s parent node to further populate the Label control:
Label1.Text += node.Text & “ “ & node.Parent.Text & “<br>”
In the end, you get a page that produces the results shown in Figure 5-13.
Specifying custom icons in the TreeView control
The TreeView control allows for a high degree of customization. You saw earlier in the chapter that you were easily able to customize the look and feel of the TreeView control by specifying one of the built-in styles. Applying one of these styles dramatically changes the appearance of the control. One of the most noticeable changes concerns the icons used for the nodes within the TreeView control. Although it is not as easy as just selecting one of the styles built into the TreeView control, you can apply your own icons to be used for the nodes within the hierarchical list of nodes.
145

Chapter 5
Figure 5-13
The TreeView control contains the properties discussed in the following table. These properties enable you to specify your own images to use for the nodes of the control.
Property |
Description |
|
|
CollapseImageUrl |
Applies a custom image next to nodes that have been expanded to |
|
show any of their child nodes and have the capability of being |
|
collapsed. |
ExpandImageUrl |
Applies a custom image next to nodes that have the capability of |
|
being expanded to display their child nodes. |
LeafImageUrl |
Applies a custom image next to a node that has no child nodes |
|
and is last in the hierarchical chain of nodes. |
|
|
146

|
|
Site Navigation |
|
|
|
|
Property |
Description |
|
|
|
|
NoExpandImageUrl |
Applies a custom image to nodes that, for programmatic reasons, |
|
|
cannot be expanded or to nodes that are leaf nodes. This is pri- |
|
|
marily used for spacing purposes to align leaf nodes with their |
|
|
parent nodes. |
|
ParentNodeImageUrl |
Applies a custom image only to the parent nodes within the |
|
|
TreeView control. |
|
RootNodeImageUrl |
Applies a custom image next to only the root nodes within the |
|
|
TreeView control. |
|
|
|
Listing 5-11 shows an example of these properties in use.
Listing 5-11: Applying custom images to the TreeView control
<asp:TreeViewTreeView ID=”TreeView1” Runat=”server” Font-Underline=”false” DataSourceId=”Xmldatasource1” CollapseImageUrl=”Images/CollapseImage.gif” ExpandImageUrl=”Images/ExpandImage.gif” LeafImageUrl=”Images/LeafImage.gif”>
<DataBindings>
<asp:TreeNodeBinding DataMember=”Hardware” Text=”Computer Hardware” /> <asp:TreeNodeBinding DataMember=”Item” TextField=”Category” /> <asp:TreeNodeBinding DataMember=”Option” TextField=”Choice” />
</DataBindings>
</asp:TreeView>
Specifying these three images to precede the nodes in your control overrides the default values of using a plus (+) sign and a minus (–) sign for the expandable and collapsible nodes. It also overrides simply using an image for any leaf nodes when by default nothing is used. Using the code from Listing 5-11, you get something similar to the results illustrated in Figure 5-14.
Specifying lines used to connect nodes
Because the TreeView control shows a hierarchical list of items to the end user, you sometimes want to show the relationship between these hierarchical items more explicitly than it is shown by default with the TreeView control. One possibility is to show line connections between parent and child nodes within the display. Simply set the ShowLines property of the TreeView control to True (by default, this property is set to False):
<asp:TreeViewTreeView ID=”TreeView1” Runat=”server” Font-Underline=”false” DataSourceId=”Xmldatasource1” ShowCheckBoxes=”leaf” ShowLines=”True”>
...
</asp:TreeViewTreeView>
This code gives the result shown in Figure 5-15.
147

Chapter 5
Figure 5-14
Figure 5-15
If the ShowLines property is set to True, you can also define your own lines and images within the TreeView control. This is quite easy to do because Visual Studio 2005 provides you with an ASP.NET TreeView Line Image Generator tool. This tool enables you to visually design how you want the lines
148

Site Navigation
and corresponding expanding and collapsing images to appear. After you have it set up as you want, the tool then creates all the necessary files for any of your TreeView controls to use.
To get at the tool, move to the Design view of your file and click open the smart tag for the TreeView control that is on your page. Here you find the option Customize Line Images. Click this and you are presented with the ASP.NET TreeView Line Image Generator dialog (shown in Figure 5-16).
Figure 5-16
From within this dialog, you can select the images used for the nodes that require an Expand, Collapse, or NoCollapse icon. You can also specify the color and style of the lines that connect the nodes. As you create your styles, a sample TreeView control output is displayed for you directly in the dialog based on how your styles are to be applied. The final step is to choose the output of the files that this dialog will create. When you have completed this step, click the OK button. This generates a long list of new files to the folder that you specified in the dialog. By default, the ASP.NET TreeView Line Image Generator wants you to name the output folder TreeLineImages, but feel free to name it as you wish. If the folder doesn’t exist in the project, you will be prompted to allow Visual Studio to create the folder for you. Once in place, the TreeView control can use your new images and styles by setting the LineImagesFolderUrl property as shown here:
<asp:TreeViewTreeView ID=”TreeView1” Runat=”server” ShowLines=”true”
DataSourceId=”SiteMapDataSource1” LineImagesFolderUrl=”TreeViewLineImages”>
The important properties are shown in bold. The ShowLines property must be set to True. After it is set, it uses the default settings displayed earlier, unless you have specified a location where it can retrieve custom images and styles using the LineImagesFolderUrl property. As you can see, this simply points to the new folder, TreeViewLineImages, that you created and which contains all the new images and styles. Take a look in the folder. It is interesting to see what is output by the tool.
149