R
Roger Frei
Hello ng,
I have a datagrid that is bound to a datasource. That works good so far. Now
I want to add another column to my grid dynamically. That also works good
until the first postback. The column is still there but for some reason its
content is empty. I added the code underneath this post. The problem is that
the delegate CreateCellTemplate is not called anymore. But why? I can't
understand.. :-( Viewstate is enabled for the grid.
Code
(The grid is an infragistics one. however, i think that has no impact in
that case.)
protected void Page_Load(object sender, EventArgs e) {
if (!Page.IsPostBack) {
// add column dynamically to grid
TemplatedColumn col = new TemplatedColumn(true);
col.CellTemplate = new CompiledTemplateBuilder(new
BuildTemplateMethod(CreateCellTemplate));
myGrid.Columns.Insert(1, col);
}
}
private void CreateCellTemplate(Control container) {
CellItem currentItem = (CellItem) container;
// cast it into my business object
InvoiceEntity dataItem = (InvoiceEntity)currentItem.DataItem;
CheckBox chkBox = new CheckBox();
chkBox.ID = "baseList." + dataItem.Id;
container.Controls.Add(chkBox);
}
Thanks in advance for your help!
Regards Roger
I have a datagrid that is bound to a datasource. That works good so far. Now
I want to add another column to my grid dynamically. That also works good
until the first postback. The column is still there but for some reason its
content is empty. I added the code underneath this post. The problem is that
the delegate CreateCellTemplate is not called anymore. But why? I can't
understand.. :-( Viewstate is enabled for the grid.
Code
(The grid is an infragistics one. however, i think that has no impact in
that case.)
protected void Page_Load(object sender, EventArgs e) {
if (!Page.IsPostBack) {
// add column dynamically to grid
TemplatedColumn col = new TemplatedColumn(true);
col.CellTemplate = new CompiledTemplateBuilder(new
BuildTemplateMethod(CreateCellTemplate));
myGrid.Columns.Insert(1, col);
}
}
private void CreateCellTemplate(Control container) {
CellItem currentItem = (CellItem) container;
// cast it into my business object
InvoiceEntity dataItem = (InvoiceEntity)currentItem.DataItem;
CheckBox chkBox = new CheckBox();
chkBox.ID = "baseList." + dataItem.Id;
container.Controls.Add(chkBox);
}
Thanks in advance for your help!
Regards Roger