I've been able to add templates in code-behind using my own iTemplate class. I'm having problems getting the editItemTemplate to work.
I've tried a dozen variations and approaches - I can't find a single working example of adding both items, and editItemTemplates anywhere on the intarwebs.
Issues:
1) The edit text boxes don't appear after clicking the edit button, the row goes blank
2) I'm using Page_Init, only if not postback to add the columns to the grid
3) After paging, data disappears from the grid.
4) After clicking edit, ALL of the data in the template columns go away.
//add item templates
public class RadGridEditTemplate : ITemplate
{
protected TextBox txtBox;
private string colname;
public RadGridEditTemplate(string cName)
{
colname = cName;
}
public void InstantiateIn(System.Web.UI.Control container)
{
TextBox t = new TextBox();
t.ID = colname;
t.Width=Unit.Percentage(100);
container.Controls.Add(t);
}
}
//add edit template
public class RadGridEditTemplate : ITemplate
{
protected TextBox txtBox;
private string colname;
public RadGridEditTemplate(string cName)
{
colname = cName;
}
public void InstantiateIn(System.Web.UI.Control container)
{
TextBox t = new TextBox();
t.ID = colname;
t.Width=Unit.Percentage(100);
container.Controls.Add(t);
}
}
//code that attaches column templates to the grid
GridTemplateColumn col = new GridTemplateColumn();
rg.MasterTableView.Columns.Add(col);
col.HeaderText = header;
col.AllowFiltering = true;
col.DataField = dataField;
col.UniqueName = dataField;
col.Display = visible;
col.ItemTemplate = new RadGridTemplate(dataField);
col.EditItemTemplate = new RadGridEditTemplate(dataField);
I've tried a dozen variations and approaches - I can't find a single working example of adding both items, and editItemTemplates anywhere on the intarwebs.
Issues:
1) The edit text boxes don't appear after clicking the edit button, the row goes blank
2) I'm using Page_Init, only if not postback to add the columns to the grid
3) After paging, data disappears from the grid.
4) After clicking edit, ALL of the data in the template columns go away.
//add item templates
public class RadGridEditTemplate : ITemplate
{
protected TextBox txtBox;
private string colname;
public RadGridEditTemplate(string cName)
{
colname = cName;
}
public void InstantiateIn(System.Web.UI.Control container)
{
TextBox t = new TextBox();
t.ID = colname;
t.Width=Unit.Percentage(100);
container.Controls.Add(t);
}
}
//add edit template
public class RadGridEditTemplate : ITemplate
{
protected TextBox txtBox;
private string colname;
public RadGridEditTemplate(string cName)
{
colname = cName;
}
public void InstantiateIn(System.Web.UI.Control container)
{
TextBox t = new TextBox();
t.ID = colname;
t.Width=Unit.Percentage(100);
container.Controls.Add(t);
}
}
//code that attaches column templates to the grid
GridTemplateColumn col = new GridTemplateColumn();
rg.MasterTableView.Columns.Add(col);
col.HeaderText = header;
col.AllowFiltering = true;
col.DataField = dataField;
col.UniqueName = dataField;
col.Display = visible;
col.ItemTemplate = new RadGridTemplate(dataField);
col.EditItemTemplate = new RadGridEditTemplate(dataField);