Hi,
You need to create a template class to represent a dynamic template column.
public class MyTemplate : ITemplate
{
private DataControlRowType tempType;
private string colName;
public MyTemplate(DataControlRowType type, string col)
{
tempType = type;
colName = col;
}
public void InstantiateIn(Control container)
{
switch (templateType)
{
case DataControlRowType.Header:
container.Controls.Add(
break;
case DataControlRowType.DataRow:
container.Controls.Add(
break;
}
}
}
On button click, create a templated field.
TemplateField fld = new TemplatedField();
fld.ItemTemplate = new MyTemplate(DataControlRowType.DataRow, "col4");
fld.HeaderTemplate = new MyTemplate(DataControlRowType.Header, "col4");
GridView1.Columns.Add(fld);
This will add the templated column to your gridview. Note that, you need to do a databind again to view your new column.
Hope this helps.