Hello, I am trying to follow this sample
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html
to create a template grid column in a grid that in my case is contained inside a CompositeControl
First attempt, using the control OnInit event
protected
override
void
OnInit(EventArgs e)
{
base
.OnInit(e);
EnsureChildControls();
…
if
(!Page.IsPostBack)
{
var boundColumn = new GridBoundColumn();
grid.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField = "MyColumn";
GridTemplateColumn templateColumn =
new
GridTemplateColumn();
grid.MasterTableView.Columns.Add(templateColumn);
templateColumn.ItemTemplate =
new
MyTemplate(templateColumnName);
}
}
Result: the InstantiateIn method of the template is called only the first time, but in postbacks not.
Second attempt: subscribing to the page Init event
protected
override
void
OnInit(EventArgs e)
{
base
.OnInit(e);
EnsureChildControls();
Page.Init += PageInit;
…
private
void
PageInit(
object
sender, EventArgs e)
{
var boundColumn = new GridBoundColumn();
boundColumn.DataField = "MyColumn";
grid.MasterTableView.Columns.Add(boundColumn);
GridTemplateColumn templateColumn =
new
GridTemplateColumn();
templateColumn.ItemTemplate =
new
MyTemplate(templateColumnName);
grid.MasterTableView.Columns.Add(templateColumn);
Result: the template column is correctly created, but the bound one is duplicated on every postback
What's the correct way to programmatically create a template column in a composite control?
Thanks