0% found this document useful (0 votes)
47 views

How To Make Subreport With Reportviewer

This document describes how to report subreports with the reportviewer control in Visual Basic.NET. It shows code to load a main report, add datasets for subreports, and handle the subreport processing event to dynamically pass datasets to subreports. The code creates sample datasets, loads them into datatables, and adds them as report data sources for the main report and subreports.

Uploaded by

chhuon kimhak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

How To Make Subreport With Reportviewer

This document describes how to report subreports with the reportviewer control in Visual Basic.NET. It shows code to load a main report, add datasets for subreports, and handle the subreport processing event to dynamically pass datasets to subreports. The code creates sample datasets, loads them into datatables, and adds them as report data sources for the main report and subreports.

Uploaded by

chhuon kimhak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

How to report Subreport with reportviewer

Parent Report (Report2.rdlc)


Sub Report2

Sub report 3
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim sReport As String = Server.MapPath("~/Reports/Report2.rdlc")

ReportViewer1.LocalReport.ReportPath = sReport

Dim ds As New DataSet


Dim dt As New DataTable("Table1")
dt.Columns.Add("urlimage")

For i As Integer = 1 To 2
Dim a As String = New Uri(Server.MapPath("~/locimage/sur0" & i & ".jpg")).AbsoluteUri
dt.Rows.Add(a)
Next

ds.Tables.Add(dt)

'ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/rptListTitledeed.rdlc")
Dim datasource As New ReportDataSource("DataSet1", ds.Tables(0))
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(datasource)

ReportViewer1.LocalReport.EnableExternalImages = True

Dim imagePath As String = New Uri(Server.MapPath("~/locimage/sur01.jpg")).AbsoluteUri


Dim parameter As New ReportParameter("ReportParameter1", imagePath)

AddHandler ReportViewer1.LocalReport.SubreportProcessing, AddressOf


DemoSubreportProcessingEventHandler

ReportViewer1.LocalReport.SetParameters(parameter)
ReportViewer1.LocalReport.Refresh()

End Sub

Public Sub DemoSubreportProcessingEventHandler(ByVal sender As Object, ByVal e As


SubreportProcessingEventArgs)
Dim orderDetailsData As DataTable = Nothing

If (orderDetailsData Is Nothing) Then


orderDetailsData = LoadOrderDetailsData()
End If

e.DataSources.Add(New ReportDataSource("ds3", LoadOrderDetailsData3))


e.DataSources.Add(New ReportDataSource("DataSet1", orderDetailsData))

End Sub

Private Function LoadOrderDetailsData()


'Dim dataSet As New DataSet()
'dataSet.ReadXml("c:\My Reports\OrderDetailData.xml")
'LoadOrderDetailsData = dataSet.Tables(0)

Dim ds As New DataSet


Dim dt As New DataTable("DataSet1")
dt.Columns.Add("sID")
dt.Columns.Add("Name")
For i As Integer = 1 To 3
dt.Rows.Add(i, "Test name : " & i)
Next
ds.Tables.Add(dt)
LoadOrderDetailsData = ds.Tables(0)

End Function

Private Function LoadOrderDetailsData3()

Dim ds As New DataSet


Dim dt As New DataTable("DataSet1")
dt.Columns.Add("sID")
dt.Columns.Add("Name")
For i As Integer = 5 To 7
dt.Rows.Add(i, "Test name : " & i)
Next
ds.Tables.Add(dt)

Return ds.Tables(0)

End Function

You might also like