ascx") > 0)
{
repeaterRdrCust.ItemTemplate = Page.LoadTemplate(templateName);
}
The first thing the code does is check for the .ascx file extension to determine whether this
is a file-based template. Next, the code calls Page.LoadTemplate to load the template from disk.
At that point, it can assign the ITemplate reference to the ItemTemplate property of the Repeater
server control and continue with the rest of the data-binding process. Figure 7-10 demonstrates
a different layout with the template CustFileTemplate.ascx.
Selecting the CustCodeTemplate option from the DropDownList control executes a different
code path that programmatically instantiates templates and assigns them to the Repeater control:
else
{
repeaterRdrCust.HeaderTemplate = new CustCodeHeaderTemplate();
repeaterRdrCust.ItemTemplate = new CustCodeItemTemplate(true);
repeaterRdrCust.AlternatingItemTemplate = new CustCodeItemTemplate(false);
repeaterRdrCust.FooterTemplate = new CustCodeFooterTemplate();
}
326 CHAPTER 7 ?– SE RVER CONTROL DATA B INDING
Figure 7-10. The Dynamic Templates web form and CustFileTemplate.ascx
Three custom template classes are used to affect the output of Repeater:
CustCodeHeaderTemplate, CustCodeItemTemplate, and CustCodeFooterTemplate.
Pages:
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440