You need to create a class which implements
the ITemplate
interface[
^].
The InstantiateIn
method[
^] will be called with the container control, and your class should add the template controls at that point.
sealed class IDFieldTemplate : ITemplate
{
public EventHandler TextChangedHandler;
public void InstantiateIn(Control container)
{
UpdatePanel u1 = new UpdatePanel();
TextBox tb1 = new TextBox();
tb1.AutoPostBack = true;
tb1.TextChanged += TextChangedHandler;
u1.ContentTemplateContainer.Controls.Add(tb1);
container.Controls.Add(u1);
}
}
...
IDFieldTemplate template = new IDFieldTemplate();
template.TextChangedHandler += tb1_TextChanged;
TemplateField tpfield = new TemplateField();
tpfield.HeaderText = "ID"
tpfield.ItemTemplate = template;
gv.Columns.Add(tpfield);
NB: If you need to support two-way data binding, your template class will also need to implement
the IBindableTemplate
interface[
^].