开发者

Unable to display report in ASP.Net page

I have created a dataset and using it in my crystal report. Issue is that at design time i am able to display the data but when I execute it using ASP.Net page its showing a blank page. Below is my code that i am using t开发者_StackOverflowo display the report programatically:

 /// <summary>
        /// Displays batch report
        /// </summary>
        /// <param name="agreementId"></param>
        private void ShowStatements(string agreementId)
        {
            var crvStatements = new CrystalReportViewer();
            var reportDocument = new ReportDocument();
            reportDocument.Load(Server.MapPath("Statements.rpt"));
            crvStatements.ReportSource = reportDocument;
            var dt1 = new dsStatements.usp_GetBillDetailsByAgreementIdDataTable();
            var dt2 = new dsStatements.usp_GetTransactionTypesByAgreementIdForBillDataTable();
            var adapter1 = new usp_GetBillDetailsByAgreementIdTableAdapter();
            var adapter2 = new usp_GetTransactionTypesByAgreementIdForBillTableAdapter();
            adapter1.Fill(dt1, agreementId);
            adapter2.Fill(dt2, agreementId);
            //var statements = new dsStatements();
            //statements.Tables.Add(dt1);
            //statements.Tables.Add(dt2);
           // reportDocument.SetDataSource(dsStatements);

            crvStatements.RefreshReport();
        }

Please note that i haven't used any control on the page. I am adding report viewer , report source and dataset programatically. Please help me out. I need it ASAP. I am using VS2010 with CR 2010


Can you provide the reason why you are creating the Crystal Report Viewer at runtime and not simply creating the control on the page? Some people do this so that they can export without displaying, but I don't see any code for that.

I haven't tested this, but I believe the below would work if you had a viewer control on your page.

private void ShowStatements(string agreementId)
    {
        //var crvStatements = new CrystalReportViewer(); //created on the page
        ReportDocument reportDocument = new ReportDocument();
        reportDocument.Load(Server.MapPath("Statements.rpt"));
        crvStatements.ReportSource = reportDocument;
        System.Data.DataTable dt1 = new dsStatements.usp_GetBillDetailsByAgreementIdDataTable();
        System.Data.DataTable dt2 = new dsStatements.usp_GetTransactionTypesByAgreementIdForBillDataTable();
        System.Data.DataSet statements = new System.Data.DataSet();
        statements.Tables.Add(dt1);
        statements.Tables.Add(dt2);
        reportDocument.SetDataSource(dsStatements);

        crvStatements.DataBind();
    }

I'm assuming that the report is set up with these tables linked in the report, and you may have to give the datatables a name so that Crystal knows how to map each datatable to the corresponding table within the report. If possible you may try to limit the report to accepting a single table until you have the loading logic worked out.

If each of these datatables represent the data for a subreport then you'll have to iterate through those reports and set the datasources manually.

I hope this helps, but I answered this off the top of my head so there are probably things I've missed. If it doesn't work you just provide a comment and we can probably work through any issues.


The RefreshReport(); makes the Report appearing Empty. try it before loading the Datasets.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜