This is a migrated thread and some comments may be shown as answers.

Subreport parameters passed in from mainreport using NeedDatasource event

4 Answers 345 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chris Hoare
Top achievements
Rank 1
Chris Hoare asked on 05 Jan 2012, 05:36 PM

 I am using the needdatasource event on the subreport to get data:

      

 Private Sub TimesheetParityBreakdownReport_NeedDataSource(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.NeedDataSource
       
        Dim item As Telerik.Reporting.Processing.ReportItemBase = TryCast(sender, Telerik.Reporting.Processing.ReportItemBase)
        Dim dataRow As DataRow = DirectCast(item.DataObject.RawData.row, DataRow)
        Dim oDataSource As New System.Web.UI.WebControls.ObjectDataSource

        oDataSource.SelectMethod = "SafeTelerikReportNewTimesheetParityBreakdown"
        oDataSource.TypeName = "SafeTelerikReportWS.SafeTelerikReportService"
        Dim session As Guid
        session = dataRow("SessionID")

        oDataSource.SelectParameters.Add("SessionID", session.ToString)
        oDataSource.SelectParameters.Add("DivisionRef", dataRow("DivisionRef"))
        oDataSource.SelectParameters.Add("DepartmentRef", dataRow("DepartmentRef"))
        oDataSource.SelectParameters.Add("ToDate", dataRow("ToDate"))
        oDataSource.SelectParameters.Add("NoOfWeeks", dataRow("NoOfWeeks"))
        oDataSource.SelectParameters.Add("PersonnelRef", dataRow("PersonnelRef"))
        oDataSource.SelectParameters.Add("ClientRef", dataRow("ClientRef"))
        oDataSource.SelectParameters.Add("JobDescription", dataRow("JobTitle"))

        oDataSource.Select()
        oDataSource.DataBind()
        Me.DataSource = oDataSource
    End Sub

   the parameters are being passed to the subreport are stuck on the first row data values from the mainreport.

   ie I have a 100 different rows in the main report and the subreport comes out eveytime based on rows 1 values.
i need each subreport to be based on the each detail items of the main report

     

   I also need to know how to run the subreport ondemand, so that it automatically doesnt call the subreport 100 times for example.

   I have various field on the main report which i can use to show subreport. I'd like it so when i click to open one subreport, any open ones should close.

  
using Q2 2010 reporting

 Thanks

4 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 10 Jan 2012, 01:26 PM
Hi Chris,

Your question has already been answered in the other thread you've opened. Here is the answer in case anyone else is interested:

You should make appropriate changes in the code:
  • You should cast the sender to the Telerik.Reporting.Processing.Report instead of Telerik.Reporting.Processing.ReportItemBase.
  • To get the right DataObject you should use item.Parent.DataObject because item is a reference to the report used as sub report, but you need it from its container - SubReport item which is placed in the main report.
  • And at last you should set item.DataSource instead of Me.DataSource

It is more convenient if you did not use NeedDataSource event at all. If you use some of our DataSources components you can design the reports wysiwyg in the Visual Studio. Create the method that retrieves the data and use it through ObjectDataSource. We noticed that you're using the ASP.NET object data source control (System.Web.UI.WebControls.ObjectDataSource) which is incorrect. We have our own ObjectDataSource Component that should be used instead. Even more, the Data Source Components are meant for design time binding and not for programmatic binding. As my colleague suggested in previous post, we highly recommend designing and binding the reports directly in the Visual Studio designer. You can find step by step instructions on setting up master-detail in the How-To: Creating Master-Detail Reports Using SubReports help article.
You can see this implementation in action in the Invoice demo report, also a video how the report is setup is available here.


We kindly ask you to use just one support channel to contact us. Posting the same questions numerous times slows down our response time because we will need to review and address two threads instead of one. Threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.

All the best,
Steve
the Telerik team

Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
Kevin Mason
Top achievements
Rank 1
answered on 18 Sep 2012, 08:55 PM
This worked for me as an example on one way to get values for subreport SQL parameters from the master report data row (current row being processed).   Reports version Q2 2012.

Private Sub SubReport1_NeedDataSource(sender As System.Object, e As System.EventArgs) Handles SubReport1.NeedDataSource
  Dim SQL2 = _
    <SQL2>
      SELECT WORKORDER_SEQ,
             UNIT_SEQ,
             ROW_NUM,  WORKORDER_SEQ_DISPLAY, WORKORDER_ORIGIN, WORKORDER_CLASS,
             DATE_CREATED, DATE_COMPLETED, UNIT_CYCLE, PROBLEMS, FINDINGS, REPAIRS
      FROM DATASCHEMA.VIEW_LIST_WORKORDERS_HISTORY WHERE UNIT_SEQ = :p_UNIT_SEQ
    </SQL2>
  ' Get connection string
  Dim strConn As String = "Data Source=DBNAME;Persist Security Info=True;User Id=DATASCHEMA_USER;Password=loveTelerikReports"
  Using conn As New OracleConnection(strConn)
    Try
      Dim subrpt As Telerik.Reporting.Processing.SubReport = DirectCast(sender, Telerik.Reporting.Processing.SubReport)
      Dim section As Telerik.Reporting.Processing.DetailSection = DirectCast(subrpt.ParentElement, Telerik.Reporting.Processing.DetailSection)
      Dim rowdata As System.Data.DataRowView = DirectCast(section.DataObject.RawData, System.Data.DataRowView)
      Dim decUnitSeq As Decimal = CDec(rowdata.Row.ItemArray(1).ToString())
      Dim cmd2 As New OracleCommand(SQL2.Value, conn)
      cmd2.Parameters.Clear()
      cmd2.Parameters.Add("p_UNIT_SEQ", OracleDbType.Decimal, decUnitSeq, ParameterDirection.Input)
      Dim oda2 As New OracleDataAdapter(cmd2)
      Dim ds2 As New DataSet()
      oda2.Fill(ds2)
      subrpt.InnerReport.DataSource = ds2
    Catch ex As Exception
    Finally
      conn.Close()
      conn.Dispose()
    End Try
  End Using
End Sub
0
James
Top achievements
Rank 1
answered on 02 Aug 2014, 07:01 PM
Hi Steve, SO I have a question about th example: http://www.telerik.com/help/reporting/designing-reports-master-detail.html

 Imagine you have 1000 categories
On the UI you want to choose 100 categories. 
so you pass 100 categoryIds to the mater report's object data source to limit the categories being return.
How do you then pass the 100 categoryIds to the subreport so its datasource will only return the categories we are interested in and not return all the categories and then rely on the report filter to limit the categories ?
0
Stef
Telerik team
answered on 06 Aug 2014, 02:56 PM
Hi James,

If you use the approach described in the How to: Create a Master-Detail Report Using a SubReport Item help article, the data in the sub report will be filtered based on the data of the master report.

You can also test the approach suggested in the How to bind the DataSource of a SubReport in the designer forum discussion to avoid using a separate data source component in the sub report.


Let us know if you need any further help.

Regards,
Stef
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
Chris Hoare
Top achievements
Rank 1
Answers by
Steve
Telerik team
Kevin Mason
Top achievements
Rank 1
James
Top achievements
Rank 1
Stef
Telerik team
Share this question
or