Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

A La Carte: Make Highly Customized Menus with Ease in ASP.NET 2.0 : Page 3

In ASP.NET 2.0, Microsoft has added a full-featured Menu control that you can use to display menus statically or dynamically, vertically or horizontally, containing either text or images. Finally, you can stop maintaining your JavaScript-based menus by hand.


advertisement
A Static Display Example
You control a Menu's static display behavior using the StaticDisplayLevels property, which indicates how many levels the control should display all the time, counting from the root of the menu. For example, if you have a Menu with three levels and you set StaticDisplayLevels to 3, the control will display all the levels statically. If you set StaticDisplayLevels to 2 instead, the control expands and displays only the first two levels statically—the third level will appear dynamically.
 
Figure 4. Static Menu Display: The figure shows the menu defined in the code from Listing 1.
Author's Note: The minimum value for the StaticDispalyLevels property is 1; the control will throw an exception if you set the StaticDisplayLevels property value to zero or to a negative number. In contrast, setting StaticDisplayLevels to a value greater than the number of levels in the menu has no adverse affect.

Listing 1 shows an ASP.NET page containing a menu that displays all its levels statically. Note that the code in Listing 1 sets the StaticDisplayLevels property value to 5. Even though the example doesn't have that many levels, the Menu control doesn't throw an exception; it simply displays all its levels as static. Figure 4 shows how the menu looks in a browser.

A Dynamic Display Example

 
Figure 5. Dynamic Menu Control. The figure shows how the dynamic menu code in Listing 2 looks when rendered in a browser.
The MaximumDynamicDisplayLevels value plays a key role in displaying menus dynamically. The property specifies how many levels of dynamically-appearing menu nodes the control should display after the initial static display level. For example, if the menu's StaticDisplayLevels property is 2 and the MaximumDynamicDisplayLevels property is 10, the first two levels would be static while the next ten levels would be dynamic. Listing 2 contains an example. When you compare the code Listing 2 with that in Listing 1, note that the MaximumDynamicDisplayLevels property is the only addition needed to display the Menu dynamically. Apart from that, Listing 2 adds the StaticSubMenuIndent property to keep the menu indentation consistent. Figure 5 shows how the dynamic version appears in a browser.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap