We dynamically create GridTemplateColumn with an inner usercontrol but my usercontrol does not get initialized so whenever I try to access the controls inside it, those are all null.
Is there something I miss??
Bellow is the page codebehind and the ItemTemplate class.
The usercontrol PerformanceObjectiveControl only contains a asp:TextBox control and has a property called Text which (for now) is only a façade to the TextBox.Text itself.
Thanks,
Hugues
Is there something I miss??
Bellow is the page codebehind and the ItemTemplate class.
| ConfigureGrid() |
| { |
| ... OrenGrid.MasterTableView.Columns.Add(CreateItemTemplateColumn("Oren2")); |
| ... |
| } |
| private GridColumn CreateItemTemplateColumn(string fieldName) |
| { |
| GridTemplateColumn templateColumn = new GridTemplateColumn(); |
| templateColumn.ItemTemplate = new MyEditTempate(fieldName); |
| templateColumn.HeaderText = fieldName; |
| templateColumn.DataField = fieldName; |
| return (templateColumn); |
| } |
| internal class MyEditTempate : IBindableTemplate |
| { |
| private const string m_MyEditTemplateId = "MyEditTemplateTextBox"; |
| private readonly string m_FieldName; |
| public MyEditTempate(string fieldName) |
| { |
| m_FieldName = fieldName; |
| } |
| public void InstantiateIn(Control container) |
| { |
| Control control = container.Page.LoadControl(typeof(PerformanceObjectiveControl), new object[] { }); |
| control.ID = m_MyEditTemplateId; |
| control.DataBinding += DataBindControl; |
| container.Controls.Add(panel); |
| panel.Controls.Add(control); |
| } |
| private void DataBindControl(object sender, EventArgs e) |
| { |
| PerformanceObjectiveControl control = (PerformanceObjectiveControl)sender; |
| GridDataItem namingContainer = (GridDataItem)control.NamingContainer; |
| control.Text = ((DataRowView)namingContainer.DataItem)[m_FieldName].ToString(); |
| } |
| public IOrderedDictionary ExtractValues(Control container) |
| { |
| PerformanceObjectiveControl control = (PerformanceObjectiveControl)container.FindControl(m_MyEditTemplateId); |
| IOrderedDictionary dictionary = new OrderedDictionary(); |
| dictionary[m_FieldName] = control.Text; |
| return (dictionary); |
| } |
| } |
The usercontrol PerformanceObjectiveControl only contains a asp:TextBox control and has a property called Text which (for now) is only a façade to the TextBox.Text itself.
Thanks,
Hugues