2017年8月9日 星期三

ReportViewer 的子報表



------------------------------
//1.輸出report
private void outereport()
    {
        //ZoomPercent
        ReportViewer1.PageCountMode = PageCountMode.Actual; //顯示實際頁數
        ReportViewer1.ShowToolBar = true;
        ReportViewer1.Visible = true;
        ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing); //recallback
   
        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.ProcessingMode = ProcessingMode.Local;

        this.ReportViewer1.LocalReport.ReportPath = "oqc_report\\oqc_inspect.rdlc";
        this.ReportViewer1.LocalReport.DataSources.Clear();
        this.ReportViewer1.LocalReport.DataSources.Add(Query());
        this.ReportViewer1.AsyncRendering = false;
        this.ReportViewer1.SizeToReportContent = true;//ReportViewer1配合報表大小。 
        ReportViewer1.LocalReport.EnableExternalImages = true;


        /**************************************************/
        this.ReportViewer1.LocalReport.Refresh();
    }

//依主報表的資料,發送子報表的參數
 private void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
    {
        // 取得參數
            string spectid = e.Parameters["spectid"].Values[0];
        //取得明細資料
        DataTable tbl = this.GetDetailData(spectid);
        //繫結子報表
        e.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("defect", tbl));

    }



沒有留言:

張貼留言