How to setup generic routine to handle & bind subreport in SSRS

Traitée How to setup generic routine to handle & bind subreport in SSRS

  • mercredi 15 août 2012 18:50
     
      A du code

    my scenario is something like that i have one common report viewer in one win form and every body call that win form and pass required parameter and dataset. that form collect those data and bind ssrs report. now the problem is that a report may have 5 subreport and may have 3 subreport. that form has one event for handling subreport.

    private void reportViewer1_suberport1(object sender, SubreportProcessingEventArgs e)
    {
       
    // code here to bind subreport
    }

    whenever any person call my winform which has report viewer and if that report has subreport then person has to write code inside reportViewer1_suberport1 event to bind his report.

    my sample code for reportViewer1_suberport1 event

     private void reportViewer1_suberport1(object sender, SubreportProcessingEventArgs e)
    {
    Select Case e.ReportPath
       
    Case "subreport1"
           
    Dim tbl As DataTable = New DataTable("TableName")
           
    Dim Status As DataColumn = New DataColumn
           
    Status.DataType = System.Type.GetType("System.String")
           
    Status.ColumnName = "Status"
            tbl
    .Columns.Add(Status)
           
    Dim Account As DataColumn = New DataColumn
           
    Account.DataType = System.Type.GetType("System.String")
           
    Account.ColumnName = "Account"
            tbl
    .Columns.Add(Account)
           
    Dim rw As DataRow = tbl.NewRow()
            rw
    ("Status") = core.GetStatus
            rw
    ("Account") = core.Account
            tbl
    .Rows.Add(rw)
            e
    .DataSources.Add(New ReportDataSource("ReportDatasourceName", tbl))
       
    Case "subreport2"
            core
    .DAL.cnStr = My.Settings.cnStr
            core
    .DAL.LoadSchedule()
            e
    .DataSources.Add(New ReportDataSource("ScheduledTasks", _
                                                   
    My.Forms.Mother.DAL.dsSQLCfg.tSchedule))
       
    Case "subreport3"
            core
    .DAL.cnStr = My.Settings.cnStr
           
    Dim dt As DataTable = core.DAL.GetNodesForDateRange(DateAdd("d", _
                                                                         
    -1 * CInt(e.Parameters("NumberOfDays").Values(0)), _
                                                                         
    Today), _
                                                                 
    Now)
            e
    .DataSources.Add(New ReportDataSource("Summary", dt))
    End Select

    End Sub

    i need a good way for write generic code inside the above routine as a result any number of subreport can be bind. please put some light & guide me. thanks

Toutes les réponses

  • mercredi 22 août 2012 07:13
    Modérateur
     
     Traitée

    Hi Mou_kolkata,

    Sorry for the delay.

    Currently, the SubreportProcessing event is necessary to process the subreport in a main report when we use the ReportViewer control that runs in local processing mode.

    Besides, please note that:

    • The SubreportProcessing event is triggered for every instance of the subreport in the main report, and not just for each subreport definition.
    • If the main report has several subreports, we can examine the ReportPath property of the SubreportProcessingEventArgs class to determine which subreport is being processed and supply data for that subreport.

    Reference:
    LocalReport.SubreportProcessing Event

    Regards,
    Mike Yin


    Mike Yin

    TechNet Community Support