Create a Template class (MyTemplate class, Listing 2 –TemplateClass for
DataList) that implements ITemplate interface.
Create a constructor for the class that takes ListItemType as argument
so that we can determine whether we are constructing HeaderTemplate, ItemTemplate
or FooterTemplate. Also, we can make it through by exposing ListItemType as
Implement the InstantiateIn (Control container) method and construct the
corresponding template from the input gotten from the constructor. Refer to the
code (Listing 2 –TemplateClass for DataList and Listing 5 –TemplateClass for
GridView) for a clear understanding.
For data binding and child control that require data binding, create a
data binding event to fill the data with the control. This event will be raised
after the template items are created with all its controls.
The above 4 steps have been implemented in the code, Listing 2
–TemplateClass for DataList and
Listing 5 –TemplateClass for GridView.