Section report with object DataSource without Fields and FetchData

Posted by: uw on 7 August 2023, 11:28 pm EST

    • Post Options:
    • Link

    Posted 7 August 2023, 11:28 pm EST

    Hello,

    I have just been experimenting with Section Reports and Object DataSources. In doing so, I found that I can do this without Fields collection and FetchData. Since I can’t find anything to this effect in the help, I’m wondering if my code is ok and will work reliably.

    I have a class, e.g. “Customer”

    with a property “CompanyName”

    and a property “Persons” which is a List,

    where the class Person has the properties “FirstName” and “LastName”.

    A section report should show

    the company name in the report header and

    the persons in the detail section.

    I pass an instance of customer in the constructor of the report and have the following code in DataInitialize:

    //company data (txtCompanyName is in report header):

    txtCompanyName.Value = customer.CompanyName;

    //Person data (txtPerson* are in details section):

    this.DataSource = customer.People;

    txtPersonFirstName.DataField = nameof(Person.FirstName)

    txtPersonLastName.DataField = nameof(Person.LastName)

    This works perfectly and shows the expected data, without using the Fields collecion oder writing code in FetchData.

    Is this Ok?

    Thanks,

    Usch Wildt

  • Posted 8 August 2023, 8:40 pm EST

    Hi Usch,

    In your case, as you have a single Customer i.e. a single company name to be displayed in the report header this approach will work as assigning your list of Persons to the ‘report.DataSource’ will only enumerate through the list of persons for only one customer during the entire report execution.

    However, if you have a list of ‘Customer’ which further contains a list of ‘Persons’ in each Customer class then you’ll need to manually handle the data by assigning them to the field collection in the FetchData event.

    But when having a single Customer class this approach will work as expected.

    Regards,

    Anand

  • Posted 8 August 2023, 10:13 pm EST

    Great, thank you!

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels