Crystal 报告查看器下一页已关闭子报告选项卡,return 到主报告第二页
Crystal Report Viewer Next Page Closed sub report tab and return to main report second page
我有一个主报告和两个子报告按需显示,我的问题是点击子报告
link 一切都很好,第一页将显示子报告,但如果我想转到下一页或将子报告导出为 pdf,则只会导出主报告。如果我想转到下一页 crystal 报告查看器关闭了我的子报告选项卡并返回到第二个主要报告页面
我的 CrystalReportViewerPage.cs class
public partial class CrystalReportViewerPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
CrystalReportViewer1.ReportSource = (ReportDocument)Session["Report"];
}
else
{
if (string.IsNullOrEmpty(Page.RouteData.Values["userId"].ToString()))
throw new ArgumentNullException();
var userId = Guid.Parse(Page.RouteData.Values["userId"].ToString());
CrystalReportViewer1.ReportSource = CrystalController.Statements[userId];
Session["Report"] = CrystalController.Statements[userId];
}
}
}
和aspx页面
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CrystalReportViewerPage.aspx.cs" Inherits="Mahya.ITS.CityMan.Views.Shared.CrystalReportViewerPage" %>
<%@ Register TagPrefix="CR" Namespace="CrystalDecisions.Web" Assembly="CrystalDecisions.Web, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<script src='<%=ResolveUrl("~/Content/crystalreportviewers/js/crviewer/crv.js")%>' type="text/javascript"></script>
<body style="margin: auto;">
<form id="form1" runat="server">
<div style="text-align: center; margin: auto; direction: rtl; display: table" >
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" BestFitPage="True"
ToolPanelView="None" EnableTheming="True" HasToggleGroupTreeButton="False" HasCrystalLogo="False" />
</div>
</form>
</body>
</html>
CrystalDecisions.Web dll 版本=13.0.4000.0
等了好几个小时,终于找到问题了。必须在 OnInit 中而不是 page_load 事件中初始化报表查看器的来源。所以一切都很好,报告来源不会再重新填充。
protected void CrystalReportViewer1_OnInit(object sender, EventArgs e){
if (string.IsNullOrEmpty(Page.RouteData.Values["userId"].ToString()))
throw new ArgumentNullException();
var userId = Guid.Parse(Page.RouteData.Values["userId"].ToString());
CrystalReportViewer1.ReportSource = CrystalController.Statements[userId];
}
我有一个主报告和两个子报告按需显示,我的问题是点击子报告 link 一切都很好,第一页将显示子报告,但如果我想转到下一页或将子报告导出为 pdf,则只会导出主报告。如果我想转到下一页 crystal 报告查看器关闭了我的子报告选项卡并返回到第二个主要报告页面 我的 CrystalReportViewerPage.cs class
public partial class CrystalReportViewerPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
CrystalReportViewer1.ReportSource = (ReportDocument)Session["Report"];
}
else
{
if (string.IsNullOrEmpty(Page.RouteData.Values["userId"].ToString()))
throw new ArgumentNullException();
var userId = Guid.Parse(Page.RouteData.Values["userId"].ToString());
CrystalReportViewer1.ReportSource = CrystalController.Statements[userId];
Session["Report"] = CrystalController.Statements[userId];
}
}
}
和aspx页面
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CrystalReportViewerPage.aspx.cs" Inherits="Mahya.ITS.CityMan.Views.Shared.CrystalReportViewerPage" %>
<%@ Register TagPrefix="CR" Namespace="CrystalDecisions.Web" Assembly="CrystalDecisions.Web, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<script src='<%=ResolveUrl("~/Content/crystalreportviewers/js/crviewer/crv.js")%>' type="text/javascript"></script>
<body style="margin: auto;">
<form id="form1" runat="server">
<div style="text-align: center; margin: auto; direction: rtl; display: table" >
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" BestFitPage="True"
ToolPanelView="None" EnableTheming="True" HasToggleGroupTreeButton="False" HasCrystalLogo="False" />
</div>
</form>
</body>
</html>
CrystalDecisions.Web dll 版本=13.0.4000.0
等了好几个小时,终于找到问题了。必须在 OnInit 中而不是 page_load 事件中初始化报表查看器的来源。所以一切都很好,报告来源不会再重新填充。
protected void CrystalReportViewer1_OnInit(object sender, EventArgs e){
if (string.IsNullOrEmpty(Page.RouteData.Values["userId"].ToString()))
throw new ArgumentNullException();
var userId = Guid.Parse(Page.RouteData.Values["userId"].ToString());
CrystalReportViewer1.ReportSource = CrystalController.Statements[userId];
}