Binding to dynamic type with ObjectDataSource

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

    Posted 04 Jul Link to this post

    Hello,

    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?

    Thanks.

     

  2. Answer
    Katia
    Admin
    Katia avatar
    309 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.



    Regards,
    Katia
    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 banner
  4. Baran
    Baran avatar
    4 posts
    Member since:
    Apr 2012

    Posted 09 Nov Link to this post

    Are there any updates on the new version about this?
  5. Baran
    Baran avatar
    4 posts
    Member since:
    Apr 2012

    Posted 09 Nov Link to this post

    I am trying to conver JObject to an anonymous type. Maybe somebody can help me.

    http://stackoverflow.com/questions/40507909/convert-jobject-to-anonymous-object

  6. Baran
    Baran avatar
    4 posts
    Member since:
    Apr 2012

    Posted 09 Nov Link to this post

    I am trying to find different solutions.

    http://stackoverflow.com/questions/40507909/convert-jobject-to-anonymous-object

  7. Katia
    Admin
    Katia avatar
    309 posts

    Posted 09 Nov Link to this post

    Hi Baran,

    It is not in our short-term plans to add support for dynamic types by ObjectDataSource component.

    You can still test if the approach provided in How to: Use ObjectDataSource with ExpandoObject KB article can be useful in your scenario.


    Regards,
    Katia
    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
  8. Baran
    Baran avatar
    4 posts
    Member since:
    Apr 2012

    Posted 10 Nov in reply to Katia Link to this post

    I found a solution, maybe telerik can help us by supporting json data as datasource object.

    http://stackoverflow.com/a/40532370/202036

  9. Katia
    Admin
    Katia avatar
    309 posts

    Posted 10 Nov Link to this post

    Hello Baran,

    For JSON data, the recommended approach is first to deserialize it and then use in ObjectDataSource.


    Regards,
    Katia
    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
Back to Top
DevCraft banner