Add(footer);
}
Creating the Hyperlink Section
The middle of the code for the CreateControlHierarchy method adds the items in the menu
using the ASP.NET HyperLink control. The data for the process is provided by the ArrayList
collection exposed by the private menuData field that we instantiated in the constructor for our
control.
The first task in building each hyperlink is iterating through the menuData ArrayList. We
use a loop and a counter to help us track when we need to apply the MenuSeparatorTemplate
template to separate the hyperlinks. The loop drives retrieval of the instances of the MenuItemData
class from the collection and the execution of the CreateMenuItem helper method:
int count = menuData.Count;
for (int index = 0; index < count; index++)
{
MenuItemData itemdata = (MenuItemData) menuData[index];
CreateMenuItem(itemdata.Title, itemdata.Url,itemdata.ImageUrl, itemdata.Target);
if (index != count-1)
{
if (SeparatorTemplate != null)
{
SeperatorTemplateContainer separator = new SeperatorTemplateContainer ();
SeparatorTemplate.InstantiateIn(separator);
Controls.Add(separator);
}
else
{
Controls.Add(new LiteralControl(" | "));
}
}
}
CHAPTER 6 ?– SERVER CONTROL TEMPLATES 261
CreateMenuItem creates an ASP.
Pages:
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371