Tuesday, September 20, 2016

Dynamically bind data to an rdlc report and load report within a popup window (Part2)


To display the report within another popup window, you have to add some lines to the same code.

Just remove the last line of this method and modify the method as shown as below.

[code] private void getDataSetNames(DataTable[] datatables) { ReportDataSourceCollection dataSources = ReportViewer1.LocalReport.DataSources; this.ReportViewer1.LocalReport.DataSources.Clear(); IList dataSetNames; dataSetNames = this.ReportViewer1.LocalReport.GetDataSourceNames(); for (int i = 0; i < dataSetNames.Count; i++) { dataSources.Add(new ReportDataSource(dataSetNames[i], datatables[i])); } this.ReportViewer1.DataBind(); this.ReportViewer1.LocalReport.Refresh(); } [/code]

Modified method


[code] private void getDataSetNames(DataTable[] datatables) { ReportDataSourceCollection dataSources = ReportViewer1.LocalReport.DataSources; this.ReportViewer1.LocalReport.DataSources.Clear(); IList dataSetNames; dataSetNames = this.ReportViewer1.LocalReport.GetDataSourceNames(); for (int i = 0; i < dataSetNames.Count; i++) { dataSources.Add(new ReportDataSource(dataSetNames[i], datatables[i])); } this.ReportViewer1.DataBind(); string format = "PDF"; string deviceInfo = null; Byte[] results; string fileName = Server.MapPath("../") + "pdf\\report.pdf";//PDF location if (System.IO.File.Exists(fileName)) { System.IO.File.Delete(fileName); } results = ReportViewer1.LocalReport.Render(format, deviceInfo); string p; p = Request.Url.ToString(); string[] parts = p.Split('/'); string[] b = new string[4]; b[0] = parts[0]; b[1] = parts[1]; b[2] = parts[2]; b[3] = parts[3];//change the array items count according the path of the pdf file string a4 = string.Join("/", b); using (FileStream stream = File.OpenWrite(fileName)) { stream.Write(results, 0, results.Length); } Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "ClosePopup", "var popup=window.open('" + a4 + "/pdf/report.pdf','CustomerStatement','toolbar=no,menubar=no,status=yes');popup.focus();", true); ReportViewer1.Visible = false; } [/code]

No comments:

Post a Comment