Binding to dynamic type with ObjectDataSource

2 posts, 1 answers
  1. Mike
    Mike avatar
    59 posts
    Member since:
    Jan 2008

    Posted 04 Jul Link to this post


    I have an object data source pointing at a of List<DynamicJsonObject>. The problem is that the report throws an error when I reference a field name because it doesn't think the field exists. So, if I create a textbox and do "=Fields.LocationName", it gets an error when I preview it. However, this code works:

    private void detail_ItemDataBound(object sender, EventArgs e)
                var detail = (Telerik.Reporting.Processing.DetailSection)sender;
                Telerik.Reporting.Processing.TextBox txt = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.GetChildByName(detail, "txtLocationName");
                var data = (dynamic)detail.DataObject.RawData;
                txt.Value = data.LocationName;


    This is presumably working because I can cast the raw data as dynamic. 

    I'm not wedded to this way of doing this, but I do need a way to report on json data. Is this possible?



  2. Answer
    Katia avatar
    242 posts

    Posted 05 Jul Link to this post

    Hello Mike,

    Dynamic objects are not supported by ObjectDataSourceComponent out-of-the-box as the reporting engine expects the collection to contain a list of business objects with known properties.

    You can check the approach suggested in How to: Use ObjectDataSource with ExpandoObject KB article where a custom descriptor is provided in order to determine the actual properties of the object.

    You can test modifying the suggested approach to work in your particular scenario and with the type of objects you use.

    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft R3 2016 release webinar banner
Back to Top