Click here to Skip to main content
14,028,549 members
Rate this:
 
Please Sign up or sign in to vote.
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;};
}
</subclass></string>


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.
Posted
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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));
}
   
v2
Comments
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?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

i create a method, using reflection to find property, in rdlc call the method and get the value...
   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.190419.4 | Last Updated 27 Mar 2012
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100