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

3 posts, 0 answers
  1. T
    T avatar
    2 posts
    Member since:
    Feb 2019

    Posted 10 Apr Link to this post

    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. Todor
    Admin
    Todor avatar
    321 posts

    Posted 15 Apr Link to this post

    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
  3. T
    T avatar
    2 posts
    Member since:
    Feb 2019

    Posted 22 Apr in reply to Todor Link to this post

    Thank you! I must have missed that piece. I will add the objectDataSource1 as the datasource for the report and try again. Thanks. 
Back to Top