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

Combine two data sources into a single ObjectDataSource

1 Answer 282 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rushi
Top achievements
Rank 1
Rushi asked on 26 Jul 2010, 04:06 AM
Hello,

I am using the latest evaluation version of Telerik Report Control. I am running into a problem where I have to get data from two different objects and then combine them into a single DataSource object. Here's my problem in detail:

1. In the code below, I have two classes A and G that get data from two different data sources. Either of them or both can be null.
2. I want my Telerik report to read both the data sources and then print the results. However, since I cannot define two different data sources to a single report, I thought of combining them into a bigger class and making that class as a DataSource to the report.
3. The class ReportData serves as a container class that holds a List of the two types of objects, A and G.
4. I then return the ReportData object from TheData class. The TheData class is defined as the ObjectDataSource for the Telerik report.
5. When I go to the designer to attach my data source fields, I am getting the intellisense and the report designer is able to detect the class hierarchy and lets me set the binding to "= Fields.a.Item.Name". However, when I try to run this report in the Preview mode, I am getting an error "An error has occured processing TextBox "textBox1". Common language runtime detected an invalid program.

I have tried quite a few options here but nothing seems to work. I cannot control how I receive the data so I need to combine the two objects somehow at my end and feed them to my Report.

Any help would be greatly appreciated.

Thanks.

   [DataObjectAttribute]
    class TheData
    {
        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public ReportData GetData()
        {
            ReportData X = new ReportData();
            X.Init();
            return X;
        }
    }

    class ReportData
    {
        public List<A> a { get; set; }
        public List<G> g { get; set; }

        public void Init()
        {
            a = new List<A>();
            g = new List<G>();
            A TheA1 = new A();
            TheA1.Name = "A1";
            A TheA2 = new A();
            TheA2.Name = "A2";
            G TheG1 = new G();
            TheG1.ID = "G1";
            G TheG2 = new G();
            TheG2.ID = "G2";
            a.Add(TheA1);
            a.Add(TheA2);
            g.Add(TheG1);
            g.Add(TheG2);
        }
    }

    public class A
    {
        public string Name { get; set; }
    }

    public class G
    {
        public string ID { get; set; }
    }

1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 28 Jul 2010, 01:26 PM
Hi Rushi Lonkar,

You should go the other way around for your scenario. You are correct that a data item can get data only from a single datasource, but you can nest data items within each other. In your case you can use another data item such as SubReport or a Table which are separate data regions and would be bound to the other datasource you need.

Kind regards,
Steve
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Rushi
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or