Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeat a RDLC ReportViewer subreport

I'm really new to RDLC so please forgive me if I'm missing something obvious.

I have some data that needs to get repeated, based on a 1:Many dataset that's linked to the main report. It's not something that can be displayed in a tabular fashion because the customers want it laid out in a specific manner, so using the Tablix control is out. I have a number of subreports based on 1:1 datasets in this main report, and everything is cool with those. I created a subreport for this new dataset and added it to the main RDLC report. Everything works fine, but it only includes the first record of the dataset.

Is it possible to repeat this subreport for each record in the dataset? I think the thing that confuses me is the main RDLC has no code that specifically loads the individual subreports, so I don't see anyplace obvious where I could include a loop or anything.

like image 424
Johnny Bones Avatar asked Sep 20 '18 14:09

Johnny Bones


People also ask

How to repeat header in RDLC?

Right-click the column or corner handle of a tablix data region, and then click Tablix Properties. In Column Headers, select Repeat header columns on each page.

How do I add a DataSet to an existing Rdlc report?

To create a dataset for the RDLC report, click Reporting under Visual C# Items. Click Report, and then click Add. The Report Wizard opens. Enter a dataset name in Name field.To choose a data source for the dataset, click New on the right of Data source drop-down combo box.

How can I print Rdlc directly without viewing?

How to print the RDLC report directly without viewing in WinRT ReportViewer? Printing reports directly without viewing is not supported. This can be achieved by exporting the reports into PDF and the resultant stream is used in the PdfDocument for printing. Initialize the ReportWriter and load the report stream.

What is [RDLC] ReportViewer control?

RDLC file] ‘ReportViewer Control’ supplied by the dot net framework. ‘C-Sharp Form’ that houses the ReportViewer control in it. The interaction between the different aspects in generating the report is shown below: We define the report elements in a template called ‘ Report Template ’. The report template holds the ‘ .RDLC ’ file extension.

How do I create a Department report in RDLC?

Add a new report item and name it MainReport.RDLC. Drag and drop a table into the report and set the data source to the Department model. Name the dataset "Department_DS". Design the table as shown below. Map the Name property to the Department column and add a SubReport to the Employees column. Right-click on the Subreport and select Properties.

How do I create a subreport from a RDLC file?

Always make sure that the name of the Subreport is same as the FileName of the Subreport without the rdlc extension. Add a table to the rdlc file, select the Employee Model as Datasource, and set the name of the dataset as Employee_DS. Map the columns of the table to the corresponding properties of the dataset.

How to point a subreport to the main report?

Now open report 1 and from toolbox drag the subreport control to this main report. 4. Then Right click on the subreport control and configure it to Point to the Report 2. 5. Configure the Parameter For subreport , if you have to pass any paramter. but i dont want this thing.


1 Answers

If you don't have particular needs I think it's important to know that you can put a Rectangle in Tablix cell and then use it as a container for simple controls as TextBox, Line, Image, etc. laied out as you want.

If you still need to use subreport you could put a SubReport in Tablix cell and solve any problem in the LocalReport.SubreportProcessing event that occurs when a subreport is processed.

If you have a lot of records you can use a single Dataset and filtered it in the SubreportProcessing event, using the subreport Parameters that you already set in Designer Mode.

Private Sub SubreportProcessingHandler(sender As Object, e As SubreportProcessingEventArgs)

    Dim dvFiltered As New DataView(Me.YourDataSet.Tables(0))

    dvFiltered.RowFilter = "Parameter1 = " & CInt(e.Parameters.Item("yourParameter1").Values(0)) & " AND " _
        & "Parameter2 = '" & CStr(e.Parameters.Item("yourParameter2").Values(0)) & "'"

    e.DataSources.Add(New ReportDataSource("YourDataSourceName", dvFiltered.ToTable("YourDataSourceName")))

End Sub

For example, using a DataSet that contains master and details data, you can build a main report grouped by IdMaster and put a subreport in details section.

main report

This is the subreport: please note that the DataSet is the same as main report but we also need 2 Parameters (IdMaster and IdRow) to display the correct data.

sub report

In the main report you need to link subreport Parameters to actual values of DataSet.

sub report parameter

Then, the most important part: the SubreportProcessingHandler event. This event is triggered for every instance of the subreport in the main report, so if you have 100 rows / 100 subreports this event is triggedered 100 times: every time you need to specify which data you want to display, so you have to filter the DataSet using the 2 Parameters (IdMaster and IdRow) defined in the previous step and filled with values coming from master report.

Private Sub SubreportProcessingHandler(sender As Object, e As SubreportProcessingEventArgs)

    Dim dvTest As New DataView(Me.dsTest.Tables(0))
    dvTest.RowFilter = "IdMaster = " & CInt(e.Parameters.Item("parIdMaster").Values(0)) & " AND " _
        & "IdRow = " & CInt(e.Parameters.Item("parIdRow").Values(0))

    e.DataSources.Add(New ReportDataSource("DataSet_TEST", dvTest.ToTable("DataSet_TEST")))

End Sub

This is the result:

result

As I stated at the beginning of the answer, if you don't have particular needs you can use a Rectangle instead of a SubReport. Regarding this example you can obtain the same result using the green Rectangle as container.

rectangle

like image 177
tezzo Avatar answered Oct 10 '22 08:10

tezzo