2014年4月9日 星期三

RDLC Subreport 讀取

設計RDLC時,通常都是習慣先在BISD(後來改叫SSDT) 建一個報表專案,然後撰寫SQL設計LAYOUT確認報表內容沒問題後再將

讀取MAIN RDLC應該不是問題

 讀取子報表,只需在原來讀取MAIN RDLC的程式碼加入以下

ReportVierwe1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SetSubReportData);

ReportViewer1.LocalReport.Refresh();

void SetSubReportData(object sender, SubreportProcessingEventArgs e)
 {

        int sn = int.Parse(e.Parameters["p_sn"].Values[0]); //子表傳遞參數值
      
        string dsname= string.Empty; //每張子表的datasetname,不同子表要給不同名
      
        DataTable dtsource =new DataTable();//報表資料來源,這里是用datatable回傳型態

        switch(e.ReportPath)  //依子表名稱(rdlc的檔名)來讀取資料
                {
                    case "rdlcname1":
                         dsname = "DS1"; //dataset name in rdlc
                         dt = datasource1; //your sql data table ,code by self
                      break;
                    case "rdlcname1":
                         dsname = "DS2"; //dataset name in rdlc
                         dt = datasource2; //your sql data table ,code by self
                      break;
                 }

           e.DataSources.Add(new ReportDataSource(dsname,dt ));  //設定來源

}

沒有留言:

張貼留言

pdf.js 無法顯示部份字

有個檔案在pdf viewer套件中無法顯示內容,但下載檔案後使用工具又可以正常顯示。 本來以為是套件版本太舊的原因,於是去下載pdf viewer套件 https://github.com/mozilla/pdf.js 更新後還是一樣。 覺得應是字型缺漏的問題,於是用PDF-X...