Thursday, February 10, 2011

Displaying single-instance business object data on SSRS

I have a SQL Server Reporting Services local (i.e. RDLC) report displayed in a ReportViewer, with two subreports. I am using business objects to populate the datasets. What is the best way to populate single-instance data on my report, e.g. a dynamic title, or a text box that lists a calculated value, not based on the report data?

I am currently displaying data using the following style:

public class MyRecordList
{
   string Name { get; set; }
   List<MyRecord> Records { get; set;}
}

public MyRecord
{
   string Description { get; set;}
   string Value { get; set;}
}

I set the datasource to the Records in an instance of MyRecordsList, and they print out find in a table. But adding a textbox and and referring to Name displays nothing. I also tried turning Name into a List, and referring to the first in the list, using:

=First(Fields!Name.Value, "Report1_MyRecordList")

but still nothing is printed on the report.

  • This would be easiest to do with a parameter to the report. Load the report in the report designer and select the Report menu and go to Parameters. Add a string parameter and give it a good name. You can then refer to the parameter in the body of the report with =Parameters.nameOfParameter.Value

    Then add this code before loading the report:

    myReportViewer.LocalReport.SetParameters(new ReportParameter[] { new ReportParameter("nameOfParameter", "parameter's value") });

    From Matt Greer

0 comments:

Post a Comment