且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用RDLC在Asp.net中生成报告,动态分配数据集

更新时间:2023-11-15 19:02:40

演练:使用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