Click here to Skip to main content
15,746,652 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi everyone,

I have the following class:

public class Test
    public string Name {get;set;}
    public List<string> stringitems {get;set;}
    public List<subclass> subclassitems {get;set;}

public class SubClass
  public string Value {get;set;};

And I want to pass this as a datasource in a RDLC report.

How is this possible I know if you have a nested type you do like this for example =Fields!SubClass.Value.Value

But i dont know about lists. And also there seems to be some problem with a List<string> type.

can anyone please help thx appreciate it.

You can accomplish this if you create a sub report for the list items and include it in your main report.

Then handle the SubreportProcessing event and set the datasource for the subreport. Sample code below.

ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SetSubDataSource);

public void SetSubDataSource(object sender, SubreportProcessingEventArgs e)
    var mainSource = ((LocalReport) sender).DataSources["DataSet1"];
    var subSource = ((List<test>)mainSource.Value).First().subclassitems;
    e.DataSources.Add(new ReportDataSource("SubDataSet1", subSource));
Share this answer
yoshito 3-Apr-12 0:38am    
hi, Question for you , I tried doing your way,
however,.. every time when I put the subreport inside a list. It throw up an error, however it works perfectly fine outside a list!

any ideas?
i create a method, using reflection to find property, in rdlc call the method and get the value...
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900