This is a migrated thread and some comments may be shown as answers.

[Solved] Dynamic usercontrol in dynamic itemtemplate not initialized

1 Answer 147 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hugues
Top achievements
Rank 1
Hugues asked on 07 May 2009, 06:45 PM
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.

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

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 11 May 2009, 03:31 PM
Hello Hugues,

May I ask you to verify whether the ConfigureGrid() method is called when Page's Init event is raised?

Please examine this online help article which is devoted on this matter.

Regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Hugues
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or