You are on page 1of 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