1

I'm new to RDLC report and I have a basic requirement which I think it should be supported. But I can't find the specific solution. So Please help me. Thank you:)

The datasource of my report is a object like this:

class Order {
    public string id {get; set;}
    public int userid {get; set;}
    public Address address {get; set;}
    public List<Package> packages {get; set;}
}

class Address {
    // Fields...
}

class Package {
    public string pNumber {get; set;}
    public string state {get; set;}
    public List<Item> items {get; set;}
}

class Item {
    public string itemName{get; set;}
    // other fields...
}

And I would like to make a report like this:

+----------+-----------+----------+----------+
| OrderId  | [orderId] | UserId   | [userId] |
+----------+-----------+----------+----------+
| Address  | [address line 1]                |
+          +---------------------------------+
|          | [address line 2]                |
+----------+---------------------------------+
|                  Packages                  |
+--------------------------------------------+
| package1 | pNumber   | [pnumber]           |
+          +-----------+---------------------+
|          | State     | [state]             |
+          +-----------+---------------------+
|          | Items     | ItemName | ItemSize |
+          +           +----------+----------+
|          |           | item1    | 111      |
+          +           +----------+----------+
|          |           | item2    | 222      |
+----------+-----------+----------+----------+
| package2 | pNumber   | [pnumber]           |
+          +-----------+---------------------+
|          | State     | [state]             |
+          +-----------+---------------------+
|          | Items     | ItemName | ItemSize |
+          +           +----------+----------+
|          |           | item3    | 111      |
+          +           +----------+----------+
|          |           | item4    | 222      |
+----------+-----------+----------+----------+

So how should I bind the dataset to the report? I use the report builder and can only bind the object non-list fields to it or just the list field. Any idea/suggestion/example are welcome. Thank you.

Just4Test
  • 11
  • 3

1 Answers1

0

It looks like you would need to "flatten" your data into one DataTable and create table (in rdlc report, Tablix control) grouped by order, package and item IDs with order, address, package and item details displayed in their respective group headers. Individual items would be listed in table "detail" row.

That would be the easiest way to accomplish formatting you described too.

InitK
  • 1,261
  • 13
  • 21
  • Thank you for pointing out the solution. Could you please provide more details about how to "flatten" the objects into one DataTable and group them in the report? Maybe some code example would help me to understand... – Just4Test Dec 22 '15 at 06:14
  • Something like this could help: http://stackoverflow.com/questions/6428940/how-to-flatten-nested-objects-with-linq-expression. You would know your data better. Maybe you need to look at how your objects are being populated to start with and write entirely new query to get your flat object. As for creating table and grouping data, look at any RDLC tutorial, for example: http://tutorialhouse.weebly.com/reporting/create-rdlc-report-page-break-repeat-header-row-in-visual-studio-2010, but there are many videos and questions and answers right here on stackoverflow too. – InitK Dec 23 '15 at 16:47