How to create an ObjectDataSource class

5 posts, 1 answers
  1. Richard
    Richard avatar
    4 posts
    Member since:
    Aug 2016

    Posted 15 Sep Link to this post

    I am finding the documentation really complicated. How can I create a class to be used as an objectdatasource? When I ran the wizard I put in my class but it didn't show any of the fields. So here is my class. How can I turn this into an objectdatasource?

     

    public class MyClass
        {
            public MyClass()
            { }
            public Guid Id;
            public string Name;
            public string Description;
        }

     

    It's bigger than that, but that's the gist. I want to create a table that will list each of the items in a list of MyClass.

  2. Stef
    Admin
    Stef avatar
    3050 posts

    Posted 16 Sep Link to this post

    Hello Richard,

    Properties must be accessible (e.g. public) with get and set methods - Data Explorer does not show all or any data fields.

    Please check the DataBinding/ListboundReport example in the local demos, installed by default under C:\Program Files (x86)\Telerik\Reporting R3 2016\Examples.


    Let us know if you need further help.

    Regards,
    Stef
    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. Richard
    Richard avatar
    4 posts
    Member since:
    Aug 2016

    Posted 16 Sep in reply to Stef Link to this post

    Hi Stef, that example has the objectDataSource as the Cars class and in that class you're hard coding data. I don't want to do that. I want to pass in a list of MyClass to the report that will then populate the table with the data. So this is what I have:

     

    public class MyClass
        {
            Guid Id;
            string name;
            string description;

            public MyClass(Guid id, string name, string description)
            {
                this.id = id;
                this.name = name;
                this.description = description;
            }

            public Guid Id
            {
                get { return this.id; }
                set { this.id = value; }
            }

            public string Name
            {
                get { return this.name; }
                set { this.name = value; }
            }

            public string Description
            {
                get { return this.description; }
                set { this.description = value; }
            }
        }

     

    However when I try creating an objectdatasource on the Choose a Data Member page of the wizard in the box all I get is MyClass() whether I select No data source member or Choose a data source member. So I just click on MyClass() and then Finish. It goes back to Choose a Data Source and then I click Next. Now it's asking me to Arrange Fields but in the list of Data Source Fields all it has is objectDataSource1 listed and nothing underneath it. I am totally stuck.

  5. Answer
    Richard
    Richard avatar
    4 posts
    Member since:
    Aug 2016

    Posted 16 Sep in reply to Richard Link to this post

    Never mind I figured it out. :)
  6. Stef
    Admin
    Stef avatar
    3050 posts

    Posted 17 Sep Link to this post

    Hi Richard,

    Just to add some details about the ObjectDataSource and how it works.

    In general, the purpose of the ObjectDataSource component is to provide data to the report in a declarative manner. The ObjectDataSource.DataSource should be the assembly qualified name or Type of the data access layer (class), where the reporting engine will use System.Reflection to create the instance of the class (by using its default constructor) and to execute its method specified by the ObjectDataSource.DataMember property.

    Regards,
    Stef
    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