ASP.NET MVC VS2010 Crystal Reports Beta 2 Can't Print, Export, Zoom, or Change Pages

前端 未结 1 1656
天命终不由人
天命终不由人 2021-01-22 13:05

I just upgraded to the beta 2 of Crystal Reports for Visual Studio 2010 and I\'m not able to print, export, zoom, or change pages while using the web control in an ASP.NET MVC a

相关标签:
1条回答
  • 2021-01-22 13:44

    Crystal Report's Report Viewer control is a server side control, as such, it doesn't function properly when part of an MVC view page. Hence, when I tried to print or export, causing a post back, I would continually see a page refresh, instead of printing or exporting.

    This behavior is different from ASP.NET MVC version 1 that I used with Visual Studio 2008 and the version of Crystal Reports that came with VS2008. In VS2010 and, as of now beta of, Crystal Reports 2010, the Report Viewer control needs to be on a plain old aspx page and not part of an MVC view page.

    To accomplish this I took the following steps, many of these steps are the sames ones I used before in a related question, but I have tweaked them for the new behavior seen in VS2010 and CrystalReports 2010: StackOverflow.com: CrystalReportViewer Buttons Broken using MVC Framework

    • In my controller I invoke the proper calls to my model to obtain my report data,

    List<JobSummaryBody> body = model.GetJobSummaryBody(jobId, startDate, endDate);

    • Next, I create a varible for the report itself, in this case:

    JobSummaryByDate summary = new JobSummaryByDate();

    Note: JobSummaryByDate is a data type created by Crystal Reports when I design my report, it is code generated. Think of it as all of the data that your designed report is going to need.

    • Next I set the the data source, the row data, for the report I just created

    summary.SetDataSource(body);

    • Lastly I store my report data in Session, and do a Response.Redirect to my aspx page that holds the Crystal Reports Viewer

    Session["ReportData"] = summary; Response.Redirect("~/CrystalReports/JobSummaryByDateView.aspx");

    Note: I have created a new top level folder in my project called "CrystalReports", the folder can actually be navigated to by URL.

    • The source page for JobSummaryByDateView.asp is very striaght forward, add the Crystal Report Viewer, in this case I gave it an ID of Report Viewer:

      <CR:CrystalReportViewer ID="ReportViewer" runat="server" AutoDataBind="true" EnableDatabaseLogonPrompt="False" EnableParameterPrompt="False" ToolPanelView="None" HasDrilldownTabs="False" HasDrillUpButton="False" HasSearchButton="False" HasToggleGroupTreeButton="False" HasToggleParameterPanelButton="False" ReuseParameterValuesOnRefresh="True" />

    • Lastly, on the code behind page I set the ReportViewer.ReportSource to my Report Data I generated in my controller:

    protected void Page_Init(object sender, EventArgs e) { ReportViewer.ReportSource = Session["ReportData"]; }

    0 讨论(0)
提交回复
热议问题