ASP.NET Whidbey adds a huge number of productivity features and enhancements. Although it's still early in the development process, Paul Sheriff and Ken Getz dig in and start playing with some of the new features, passing along what they've found.
by Ken Getz
Paul D. Sheriff
Feb 19, 2004
Page 8 of 9
Figure 15: The bulleted list control bound to a data source makes creating lists quick and easy.
Investigating New Server Controls
As if all the previous functionality wasn't enough, the current version of ASP.NET Whidbey has added 38 new server controls! Obviously, we can't describe them all here (we haven't even managed to investigate them all), we'll try to point out some of the interesting new controls, focusing on new user interface elements and new data source controls.
It's also interesting to note that in ASP.NET Whidbey, all the server controls are device-aware. Rather than requiring you to create separate applications for rich browsers and for mobile devices, all the controls now can be used for either type of browser. ASP.NET renders the output correctly, depending on the type of device making the request for the page.
The BulletedList control allows you to display a bulleted list in almost any format you wish. (You could do this in ASP.NET 1.x using a Repeater control, but that seemed like a lot of effort.) All you have to do now is to bind this control to a data source (such as the DataSetDataSource), set the BulletStyle property to one of its many options, and it produces output that looks like Figure 15.
Figure 16: The TreeView control is ideal for navigation on Web sites.
Although it was possible in ASP.NET 1.x to download and incorporate a somewhat complex TreeView control, ASP.NET Whidbey includes a full-featured, easy-to-use TreeView control. With little or no code, you can easily bind the TreeView control to a data source, and display hierarchical data. Figure 16 shows a simple menu structure you can generate with just a little XML data and by setting a few properties.
To create your own TreeView control as shown in Figure 16, follow these steps:
In the Solution Explorer window, right-click the Data folder, and select
Add New Item from the context menu.
Select XML File from the list of templates, and name the new file Menus.xml.
In the Solution Explorer
window, double-click Menus.xml to load it into the code editor, and add the following XML data. Save the file when you're done.
<?xml version="1.0" encoding="utf-8"?>
<Menu Text="Browsing the Web Offline">
<SubMenu Text="Making Web Pages Available Offline" />
<SubMenu Text="Viewing Web Pages without being
<Menu Text="Printing and Saving Information">
<SubMenu Text="Printing and Saving Information" />
<SubMenu Text="Saving a Web Page on Your Computer" />
<SubMenu Text="Saving Text from a Web page" />
Figure 17: The TreeViewBindings Editor assists you in getting the different levels of your tree view hooked up to your XML file.
In the Solution Explorer window, right-click on the topmost node (the root folder) and select Add New Item from the context menu. Add a new Web Form, and name the page TreeView.aspx. If necessary, switch to Design view.
From the Toolbox window, select the Data tab, and drag an XmlDataSource control onto your page.
From the new control's smart tag, select the Configure DataSource link. In the Data File text box on the Configure Data Source dialog box, enter the path to your XML file (Data/Menus.xml) or click the browse button to browse to the location. Click Finish to dismiss the dialog box.
In the Toolbox window, select the Core tab, and add a TreeView control to the page.
In the TreeView control's smart tag, select the Auto Format link, and select the Windows Help option.
In the TreeView control's smart tag, select the Connect to DataSource link, and select the XmlDataSource1 option from the list of available data sources.
Select the Edit Bindings option from the smart tag, displaying the TreeView Bindings Editor dialog box.
In the Available Bindings list, select the top item, Menus, and then click Add.
In the Binding Properties grid to the right, set the Text property to Help Topics.
In the Available Bindings list, select the next item, Menu, and then click Add.
In the Binding Properties grid to the right, set the TextField property to Text. (This indicates which attribute of the Menu item within the XML you'd like to display for this node in the TreeView control.)
In the Available Bindings list, select the next item, SubMenu, and then click Add.
In the Binding Properties grid to the right, set the TextField property to Text.
Uncheck the Auto-Generate Bindings check box in the lower left of this screen. Your dialog box should look like Figure 17.
Click the OK button to save the changes.
In the Solution Explorer window, select TreeView.aspx, and press F5 to run your project. Your page appears, showing the TreeView control as in Figure 16. (Note that pressing F5 now runs the selected pageyou don't have to set the start page explicitly.)