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

How to Populate Table on Telerik Report from objectDataSource and Render PDF.

2 Answers 1415 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
T
Top achievements
Rank 1
T asked on 10 Apr 2019, 08:02 PM

Hi, I'm very new to Telerik Reporting so please excuse the very basic question :)

I have a solution with multiple projects. The reports are in their own project.  I am trying to create the report from the website project and send a list of my data type to the objectDataSource of the report so that it can dynamically populate the report table. Then I render the report instance as a pdf to store. 

I am able to call and create the report, but I am having trouble getting the report to populate any data into the table.  The report renders but is blank other than the table headers. 

I am trying to find an example solution that does this using 2 projects, a telerik report, an object data source, and a GetData method that takes in a List<MyData> and returns the List<StuffData> so that the table can be populated. Is this doable or is there a better way to pass a list of data to the report so that it can dynamically populate the table on the report? 

Telerik.Reporting.ObjectDataSource objectDataSource1 = new Telerik.Reporting.ObjectDataSource();
        List<StuffData> stuffDataList = new List<StuffData>();

//This is just an example. The list will be populated from user selections adding to the list. 
        for (int i = 1; i < 3; i++)
        {
            int dummyNumber = 999999999 - i;
            StuffData stuffData = new StuffData()
            {
                stuffAddress = i + "Main Street",
                stuffDataId = i,
                stuffSource = "Source " + i,
                stuffName = "Big Corp #" + i,
                stuffNumber = dummyNumber.ToString()
            };
            stuffDataList.Add(stuffData );
        }

//Class in the report project that contains the GetStuffData method to return the list of stuff.  I couldn't find a way to pass a List<StuffData> in as a report 

//parameter

        objectDataSource1.DataSource = typeof(StuffDataAccess);
        objectDataSource1.DataMember = "GetStuffData";
        objectDataSource1.Parameters.Add(new Telerik.Reporting.ObjectDataSourceParameter("stuffDataList", typeof(List<StuffData>), stuffDataList));

        ReportTemplate.StuffReviewReport stuffReviewReport =
    new ScheduledHearingTemplate.StuffReviewReport();
        stuffReviewReport.DataSource = objectDataSource1;

        ReportProcessor reportProcessor = new ReportProcessor();
        Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
        instanceReportSource.ReportDocument = stuffReviewReport;
        RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);
       

Thanks in advance. 

2 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 15 Apr 2019, 12:06 PM
Hello T,

If I understood correctly, the report contains a Table that renders blank. In the code snippet I see that the report gets its DataSource by :

stuffReviewReport.DataSource = objectDataSource1;

I cannot see where the Table DataSource is assigned. Note that the Table can access directly only the data of its data source (i.e. like Fields.SomeDataField) and cannot access directly the data of the report or other data item. Try to add objectDataSource1 as data source of the Table.

Each ObjectDataSource parameter will be passed as an argument of its DataMember, and an overload of the method containing these exact arguments would be looked for by the Reporting engine through System.Reflection. The type of the ObjectDataSource parameters should implement IConvertible or an error will occur. Generally, List<MyData> cannot be passed as an ObjectDataSource parameter as it doesn't implement the Interface.

Note that you may directly assign the collection stuffDataList, or any other collection to the DataSource property of any data item, hence you may set the DataSource like :

MyTable.DataSource = stuffDataList;

or

MyTable.DataSource = StuffDataAccess.GetStuffData(myData);

where myData is the input parameter List<MyData>, and StuffDataAccess.GetStuffData returns the necessary List<StuffData>.

Regards,
Todor
Progress Telerik
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
T
Top achievements
Rank 1
answered on 22 Apr 2019, 02:46 PM
Thank you! I must have missed that piece. I will add the objectDataSource1 as the datasource for the report and try again. Thanks. 
Hazarath
Top achievements
Rank 1
commented on 21 May 2021, 03:30 PM

May I know how to get table object, myTable into report code and assign dynamically list object
Neli
Telerik team
commented on 26 May 2021, 03:16 PM

You may follow the Connecting the ObjectDataSource component to a Data Source article. Can you please give us more details on the requirements for assigning the data source dynamically?
Hazarath
Top achievements
Rank 1
commented on 29 May 2021, 02:46 PM

I am looking a solution create pdf report programmatically without report viewer and passing object to report from c# code.
Todor
Telerik team
commented on 02 Jun 2021, 12:31 PM

I suggest the article Embedded Report Engine that explains with sample code how to render reports programmatically.

You may assign the data with supported type to the DataSource property of the Report or other data item.

Tags
General Discussions
Asked by
T
Top achievements
Rank 1
Answers by
Todor
Telerik team
T
Top achievements
Rank 1
Share this question
or