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

How to create an ObjectDataSource class

4 Answers 415 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 16 Sep 2016, 01:38 AM

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.

4 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 16 Sep 2016, 09:17 AM
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
0
Richard
Top achievements
Rank 1
answered on 16 Sep 2016, 12:02 PM

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.

0
Accepted
Richard
Top achievements
Rank 1
answered on 16 Sep 2016, 07:06 PM
Never mind I figured it out. :)
0
Stef
Telerik team
answered on 17 Sep 2016, 09:30 AM
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
Tags
General Discussions
Asked by
Richard
Top achievements
Rank 1
Answers by
Stef
Telerik team
Richard
Top achievements
Rank 1
Share this question
or