1.
Create a Template class (MyTemplate class, Listing 2 –TemplateClass for
DataList) that implements ITemplate interface.
2.
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
public property.
3.
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.
4.
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.
5.
The above 4 steps have been implemented in the code, Listing 2
–TemplateClass for DataList and
6.
Listing 5 –TemplateClass for GridView.