2

I have a list of objects whose members each have a list of objects. For example, given the following 2 classes:

Class Phone
 string AreaCode
 string Description
 string Number

Class Employee
 string FirstName
 string LastName
 List<Phone> Phones

I then have multiple Employees, each with multiple Phones:

List<Employee> Employees

I'm tasked with creating an RDLC report to list the data. The format would be similar to:

First Name   Last Name   Phone.Description-1   Phone.Description-2  ...  Phone.Description-n
FirstName     LastName     Phone.Number-1           Phone.Number-2          ...  Phone.Number-n
FirstName     LastName     Phone.Number-1           Phone.Number-2          ...  Phone.Number-n
FirstName     LastName     Phone.Number-1           Phone.Number-2          ...  Phone.Number-n

I don't know how many Phones (in this example) are going to be returned from the database.

Note that the header above the Phone.Number columns are also from

List<Phone>

While these are from the database as well, they will be the same across all members of

List<Employee>.List<Phone>

(i.e. Employee1-Phone1, Employee2-Phone1, and Employee3-Phone1 will all have the same Phone1 header).

I can create an RDLC report using a

List<Employee> 

as its datasource, but have been unable to find a way to then incorporate the

List<Employee>.List<Phone>

on the same row as its parent Employee.

Is this doable in an RDLC Matrix? Or is there an "auto-generate columns" type of functionality that can be utilized?

Thank you for any help/direction/suggestion you can provide.

Addendum: I should mention that the DataSet returned from the database is exactly the format I need. However, as I don't know how many "Phone" columns will be returned, I don't have a definable schema, therefore, I cant create the report in the designer. By the same token, I can't set the datasource to the DataSet programatically, as there is no schema/grid defined on the report.

Metallicraft
  • 2,211
  • 5
  • 31
  • 52
  • Is there a limit on number of phones one can have ? If not I would suggest you to include phones as rows instead & use hierarchy. Also can you elaborate more on your scenario ? Where is the report displayed ? Console application ? Web application ? – Ondrej Svejdar Apr 12 '17 at 11:41
  • Thanks. I didn't include application type, I guess, because I didn't think it mattered. However, it's an MVC app replacing a console app. It uses the console app's stored procs. The data is returned exactly the way the console grid expects it. I don't know how many "phone" columns will be included for each "employee" (not a great example I know). So, you're suggesting a list of employees, each with a single phone number in its row (lots of duplicate employee data)? That can then be rolled up into a tablix with each row being unique employee data followed by an unknown number of phone columns? – Metallicraft Apr 12 '17 at 13:41
  • Precisely. Only other options are weird ones - like generating rldc xml file/stream on the fly and add all columns you see in the dataset. See http://stackoverflow.com/questions/28898087/generate-columns-dynamically-in-rdlc for reference. – Ondrej Svejdar Apr 12 '17 at 16:50
  • Thank you for the advice, I was able to make that work. If you want to throw up a proper Answer, I'll accept it. Thanks for your help. – Metallicraft Apr 12 '17 at 18:41

1 Answers1

0

Dynamic columns can be tricky - especially since you have no limit on how many phones can individual poses. There are ways around that - like generating/adjusting the rdlc xml file/stream on the fly by application serving the report. More such references can be found here Generate columns dynamically in RDLC

I would like to suggest instead to right-join employees with phone numbers and use hierarchy (tablix) with employee data being the "parent" and phone data being the "child".

Community
  • 1
  • 1
Ondrej Svejdar
  • 21,349
  • 5
  • 54
  • 89