Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > Programmatically create ItemTemplate using Reflection and POCO

Not answered Programmatically create ItemTemplate using Reflection and POCO

Feed from this thread
  • Posted on Oct 17, 2009 (permalink)

    Hi.

    I have a large system we are developing constantly which displays around 100 lists throughout the system. We have set up a configuration system for the lists, and 1 user control to handle them all.

    All our datasources are custom classes.

    When I need to combine two different properties of the class into 1 column, things get a bit tricky.

    Example of a custom class:
    public class Master { 
        public int ID { getset; } 
        public string Name { getset; } 
        public Child FirstChild { getset; } 
     
    public class Child { 
        public int ID { getset; } 
        public string Name { getset; } 

    Using reflection I can access the values of the Master class easily. This is the databind event of the custom ItemTemplate class:
    void control_DataBinding(object sender, EventArgs e) { 
        LiteralControl control = (LiteralControl)sender; 
        GridDataItem container = (GridDataItem)control.NamingContainer; 
        control.Text = dataItem.GetType().GetProperty("Name").GetValue(dataItem, null).ToString(); 




    But when I need values from the Child class, things get tricky. I have tried all methods thinkable to me, and am stuck with this.

    Can anyone show me how I can access the values from the Child class?

    Reply

  • Posted on Oct 22, 2009 (permalink)

    Did you try using DataBinder.Eval? Here is an example:

    var container = (GridDataItem) control.NamingContainer; 
    var value = (string)DataBinder.Eval(container.DataItem, "FirstChild.Name"); 

    --BH

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > Programmatically create ItemTemplate using Reflection and POCO
Related resources for "Programmatically create ItemTemplate using Reflection and POCO"

ASP.NET Grid Features  |  Documentation  |  Demos  |  Step-by-step Tutorial  ]