本文介绍了如何使用RDLC在Asp.net中生成报告,动态分配数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 < div> < asp:ScriptManager ID =ScriptManager1runat =server> < / asp:ScriptManager > < ; rsweb:ReportViewer ID =rvAgreementrunat =serverInteractiveDeviceInfos =(Collection)Height =274pxWidth =319px> < LocalReport ReportPath =rwAgreement.rdlc> < / LocalReport > < / rsweb:ReportViewer > < / div > =================== ====================== #regile绑定ReportViewer public void bindPrintProvisionReportPdfP() { try { belrr.FROM_DATE = Convert.ToDateTime(Request.QueryString [ strFD]。ToString()); belrr.TO_DATE = Convert.ToDateTime(Request.QueryString [ strTD]。ToString ()); belrr.CRN = Request.QueryString [ strCRN]。ToString(); ds = blladr.FETCH_PROVISION_REPORT(belrr); if (ds.Tables [ 0 ]。Rows.Count > 0 ) { DataTable dt = new DataTable(); dt = ds.Tables [ 0 ]; rptvPrintProvisionReportPdfP.LocalReport.ReportPath = rwPrintProvisionReportPdfP.rdlc; rptvPrintProvisionReportPdfP.LocalReport.DataSources.Clear(); var reportDataSource1 = new ReportDataSource( dsPrintProvisionReportPdfP,dt); rptvPrintProvisionReportPdfP.ProcessingMode = ProcessingMode.Local; rptvPrintProvisionReportPdfP.LocalReport.EnableExternalImages = true ; rptvPrintProvisionReportPdfP.LocalReport.DataSources.Add(reportDataSource1); rptvPrintProvisionReportPdfP.LocalReport.Refresh(); // rptvPrintDAFP.Visible = true; string fileName = Provision_Report _ + belrr.CRN的ToString(); 警告[]警告; string [] streamIds; string mimeType = string .Empty; string encoding = string .Empty; string extension = string .Empty; byte [] bytes = rptvPrintProvisionReportPdfP.LocalReport.Render( PDF, null , out mimeType, out 编码, out 扩展名, out streamIds, out 警告); // 现在您拥有代表PDF报告的所有字节,缓冲并发送它是给客户的。 Response.Buffer = true ; Response.Clear(); Response.ContentType = mimeType; Response.AddHeader( content-disposition, attachment; filename = + fileName + 。 + extension); Response.BinaryWrite(bytes); // 创建文件 Response.Flush(); // 将其发送给客户下载 } } catch (例外情况) { throw ex; } } #endregion ======================================= ==== 解决方案 演练:使用ReportViewer将代码中动态创建的数据集分配给本地报表 [ ^ ] RDLC到ReportViewer的动态绑定 [ ^ ] 希望它帮助 <div> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <rsweb:ReportViewer ID="rvAgreement" runat="server" InteractiveDeviceInfos="(Collection)" Height="274px" Width="319px"> <LocalReport ReportPath="rwAgreement.rdlc"> </LocalReport> </rsweb:ReportViewer> </div>=========================================#region Bind ReportViewer public void bindPrintProvisionReportPdfP() { try { belrr.FROM_DATE = Convert.ToDateTime(Request.QueryString["strFD"].ToString()); belrr.TO_DATE = Convert.ToDateTime(Request.QueryString["strTD"].ToString()); belrr.CRN = Request.QueryString["strCRN"].ToString(); ds = blladr.FETCH_PROVISION_REPORT(belrr); if (ds.Tables[0].Rows.Count > 0) { DataTable dt = new DataTable(); dt = ds.Tables[0]; rptvPrintProvisionReportPdfP.LocalReport.ReportPath = "rwPrintProvisionReportPdfP.rdlc"; rptvPrintProvisionReportPdfP.LocalReport.DataSources.Clear(); var reportDataSource1 = new ReportDataSource("dsPrintProvisionReportPdfP", dt); rptvPrintProvisionReportPdfP.ProcessingMode = ProcessingMode.Local; rptvPrintProvisionReportPdfP.LocalReport.EnableExternalImages = true; rptvPrintProvisionReportPdfP.LocalReport.DataSources.Add(reportDataSource1); rptvPrintProvisionReportPdfP.LocalReport.Refresh(); //rptvPrintDAFP.Visible = true; string fileName = "Provision_Report_" + belrr.CRN.ToString(); Warning[] warnings; string[] streamIds; string mimeType = string.Empty; string encoding = string.Empty; string extension = string.Empty; byte[] bytes = rptvPrintProvisionReportPdfP.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings); // Now that you have all the bytes representing the PDF report, buffer it and send it to the client. Response.Buffer = true; Response.Clear(); Response.ContentType = mimeType; Response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + extension); Response.BinaryWrite(bytes); // create the file Response.Flush(); // send it to the client to downlo } } catch (Exception ex) { throw ex; } } #endregion=========================================== 解决方案 Walkthrough: Assign Dataset Dynamically Created in Code to your local report with ReportViewer[^]Dynamic Binding Of RDLC To ReportViewer[^]Hope it helps 这篇关于如何使用RDLC在Asp.net中生成报告,动态分配数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-24 18:39