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
, the control will display all the levels statically. If you set StaticDisplayLevels
instead, the control expands and displays only the first two levels staticallythe 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.
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.|
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.