none
Subreport parameter woes RRS feed

  • Question

  • I have a typed dataset that contains two tableadapters. One tableadapter populates the main report and the other populates the subreport. I have the parameters for the subreport in the main report and I can get the subreport to work if a hard code a value from the main report in the SubreportProcessing event but I can't figure out how to get those values into the subreport dynamically.

    Can anyone steer me to a good resource on this topic? Most of what I've found is of no help.

    Thanks
    Thursday, June 12, 2008 5:37 PM

All replies

  • The main report can specify the parameters to pass to a subreport via the subreport properties dialog.  The parameters tab in that dialog will let you specify the name of the parameter on the subreport and the value you want to pass, which can be an expression.

    When the report is being processed, the SubreportProcessing event will fire.  The parameters that you specified in the properties dialog at design time are available from the event args via the Parameters property.  You should be able to use that collection to parameterize your data set and return the correct result set in the DataSources collection.
    Monday, June 16, 2008 10:03 PM
    Moderator
  • Thanks for your reply Brian. Maybe you can take a look at my code and see what I'm doing wrong. Thanks again.

            ReportViewer1.ProcessingMode = ProcessingMode.Local  
            Dim rpt As LocalReport = ReportViewer1.LocalReport  
            rpt.ReportPath = "Reports/reports/Report.rdlc" 
     
            rpt.DataSources.Clear()  
     
            Dim paramList As New Generic.List(Of ReportParameter)  
            paramList.Add(New ReportParameter("ID", uniqkey))  
     
            rpt.SetParameters(paramList)  
     
            ObjectDataSource1.TypeName = "GenericTableAdapters.sp_GenericTableAdapter" 
            ObjectDataSource1.SelectParameters.Clear()  
            ObjectDataSource1.SelectParameters.Add("CODE", txtCODE.Text)  
            ObjectDataSource1.SelectParameters.Add("SECT", txtSECT.Text)  
            ObjectDataSource1.DataBind()  
     
            rpt.DataSources.Add(New ReportDataSource("Generic_sp_Generic", ObjectDataSource1))  
            AddHandler rpt.SubreportProcessing, AddressOf ReportViewer1_SubreportProcessing  
            rpt.Refresh()  
          
        Protected Sub ReportViewer1_SubreportProcessing(ByVal sender As ObjectByVal e As SubreportProcessingEventArgs)  
            e.DataSources.Add(New ReportDataSource("Subreport_vwSubreport", ObjectDataSource2))  
        End Sub 

    I can display everything in the main report including the added parameter but I get that pesky Error: Subreport could not be shown. The Subreport typed DataSet that I'm trying to use for the subreport has 2 parameters, the one I passed into the main report, and one that is a field in the main report. When I add the following to the subreport processing, the subreport appears but only contains the data for the record that is hard coded.

            ObjectDataSource2.TypeName = "SubreportTableAdapters.vwSubreportTableAdapter" 
            ObjectDataSource2.SelectParameters.Clear()  
            ObjectDataSource2.SelectParameters.Add("ID", uniqkey)  
            ObjectDataSource2.SelectParameters.Add("ID2", "0615576")  
            ObjectDataSource2.DataBind() 
    Tuesday, June 24, 2008 7:09 PM
  • One thing to double check is that the name of the data source you specify in your subreport event handler matches the one used in the subreport definition.  One of the other values on the SubreportEventArgs is a list of data set names that need to be satisfied during the event.  Check that you are using exactly the correct name.

    Thursday, July 3, 2008 2:14 AM
    Moderator