我在aspx页面上有一个Crystal Report Viewer控件,它应该具有内置分页功能。Crystal Reports Viewer不会越过第2页
当我点击“下一页”按钮,第一次,我从第1页移动到第2页,但每个其他时间我点击“下一页”的报告重新加载到第2页
我在aspx页面上有一个Crystal Report Viewer控件,它应该具有内置分页功能。Crystal Reports Viewer不会越过第2页
当我点击“下一页”按钮,第一次,我从第1页移动到第2页,但每个其他时间我点击“下一页”的报告重新加载到第2页
问题可能源于在Page_Load
事件期间设置Crystal Report Viewer控件的ReportSource
。这会导致页面加载时页面信息被覆盖,所以“当前页面”在它应该为2时被重新设置为1.
作为一种简单的解决方案,您可以将设置的代码ReportSource
到Page_Init
非常感谢你! – Slovo 2015-12-16 11:23:09
转到Page_Init确实可以解决问题,但现在我遇到了关闭其报告源的问题。我想调用这些方法 report.Close(); report.Dispose(); 但我无法在Page_Init中调用它们。在不关闭连接的情况下,用户在使用报表一段时间后出现此错误:Crystal Reports例外:系统管理员配置的最大报表处理作业限制已达到 – stillsmallvoice 2016-04-28 20:50:26
@stillsmallvoice为报表源使用字段而不是本地变量,并在页面Dispose()覆盖中处理它。 – 2016-12-02 05:59:11
我以前有这个问题在Visual Studio 2008中, 安装Crystal Reports基本服务包1解决了这个问题
我有这样的问题太多,检查是否有没有其他的WebControl水晶干扰(回调问题?JavaScript?我不确定)。在我的具体情况中,Dart File Upload和Crystal在放入同一页面时相处得不好。
if (!Page.IsPostBack)
{
//Write your Report display code
crystalRep.Load(Server.MapPath("DueFD.rpt"));
crystalRep.SetDatabaseLogon(DB_UId, DB_Pass, Serv_Name, DB_Name);
CrystalReportViewer1.ReportSource = crystalRep;
// session code
ReportDocument doc = (ReportDocument)Session["ReportDocument"];
CrystalReportViewer1.ReportSource = doc;
}
else
{
ReportDocument doc = (ReportDocument)Session["ReportDocument"];
CrystalReportViewer1.ReportSource = doc;
}
手动
this.Init += new System.EventHandler(this.Page_Init).
添加在InitializeCompnent()的Page_Init()事件,并将其连接向上移动的Page_Load
内容以Page_Init()
。
在PageInIt中添加if (!IsPostBack)
条件。
protected void Page_Init(object sender, EventArgs e) {
if (!IsPostBack)
{
ReportDocument crystalReportDocument = new ReportDocumment();
crystalReportDocument.SetDataSource(DataTableHere);
_reportViewer.ReportSource = crystalReportDocument;
Session["ReportDocument"] = crystalReportDocument;
}
else
{
ReportDocument doc = (ReportDocument)Session["ReportDocument"];
_reportViewer.ReportSource = doc;
}
}
谢谢。,最佳答案。 – Ramunas 2016-11-28 08:35:35
我把所有的加载报告放在Page_Init中而不是Page_Load中。它工作正常。
对我来说,这工作得很好,直到我从13.0.1升级到13.0.10,所以清楚地改变了一些东西。
我已经尝试了上述解决方案,但是由于我们发回以更新报告参数,并且如果您没有在页面加载上设置报告参数,事实很复杂,刷新失败。所以截至今日,我还没有得到它的工作,没有在页面加载的东西。
我怀疑我可能不得不添加一些逻辑来检查已更改的参数值,并且只有在更改后才刷新报告。
把报告来源Page_Init代替的Page_Load 和报表参数的Page_Load 我认为它的工作原理大概
这对我的作品!
ReportDocument rd = new ReportDocument();
protected void Page_Load(object sender, EventArgs e)
{
string rptpath = WebConfigurationManager.AppSettings["ReportPath"].Replace("{TID}", Convert.ToString(Session["TID"]));
rd.Load(rptpath);
DataTable dtable = TemplateModel.LoadChequeData(Convert.ToString(Session["CID"]));
rd.SetDataSource(dtable);
}
protected void Page_Init(object sender, EventArgs e)
{
CrystalReportViewer1.ReportSource = rd;
}
我有一些共享的方法。我开发了可帮助呈现Crystal Reports的简单CR包装器。按原样使用此代码。请随意修改,扩展代码的任何部分。 下载链接https://1drv.ms/u/s!AlTLBrnU_bLUiaoUxcxNiRCZRQjWng
而样本如何利用包装类使用CR包装类enter code here
实现IDisposable接口。在Page_Init中设置报告源并在Page_Load事件中报告参数,并在Page_Unload事件中处理报告文档。
第二种方法使用静态类并将报表渲染到报表上,最后处理报表文档。报告源应保存到会话变量中。请注意,第二种方法并不适用于高流量的Web应用程序,因为使用了静态类。如果两个用户同时运行任何报告,则会发生冲突。
方法1
using System;
using System.Linq;
using CrystalDecisions.Shared;
using System.Configuration;
using System.Web.Configuration;
using WebReports.Models.Helpers.CrystalReports; //Reference to CR wrapper
namespace YourNamespace
{
public partial class ReportForm : System.Web.UI.Page
{
protected string _serverName;
protected string _databaseName;
protected string _schemaName;
protected string _userId;
protected string _userPassword;
protected bool _integratedSecurity;
protected string _databaseType;
//Wrapper Report Document
protected CReportDocument _reportDocument;
/// <summary>
/// Load report
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Init(object sender, EventArgs e)
{
//Wrapper object
this._reportDocument = new CReportDocument();
//These settings should be initialized from i.e. web.config in Page_PreInit
this._reportDocument.ServerName = this._serverName;
this._reportDocument.DatabaseName = String.Empty;
this._reportDocument.SchemaName = this._schemaName;
this._reportDocument.DatabaseType = CReportDatabaseType.ORACLE;
this._reportDocument.UserId = this._userId;
this._reportDocument.UserPassword = this._userPassword;
this._reportDocument.IntegratedSecurity = false;
//Get report name from query string. Define Your own method to get report name
var parReportName = Request.QueryString["reportname"];
if (String.IsNullOrEmpty(parReportName))
{
lblConfigError.Text = "Crystal Report name is not being provided.";
return;
}
//Set Report file
this._reportDocument.ReportFile = Server.MapPath("~/ReportFiles/") + parReportName;
//Set Report documant
this._reportDocument.SetReportDocument();
//Get Report Document
crViewer.ReportSource = this._reportDocument.GetReportDocument();
}
protected void Page_Load(object sender, EventArgs e)
{
CReportParameter reportParameter;
//Get parameters Your own method to provide report parameters
var parFimYear = RouteData.Values["par1"];
var parFimCityCode = RouteData.Values["par2"];
if (par1 == null || par2 == null)
{
lblConfigError.Text = "Crystal Report parameters are not being provided.";
return;
}
//Define Report Parameter
reportParameter = new CReportParameter();
reportParameter.ParameterName = "@parYear";
reportParameter.ParameterValue = parFimYear;
reportParameter.crParameterValueKind = ParameterValueKind.StringParameter;
_reportDocument.AddCReportParameter(reportParameter);
reportParameter = new CReportParameter();
reportParameter.ParameterName = "@parCityCode";
reportParameter.ParameterValue = parFimCityCode;
reportParameter.crParameterValueKind = ParameterValueKind.StringParameter;
_reportDocument.AddCReportParameter(reportParameter);
//Set report parameters
this._reportDocument.SetReportParameters();
}
protected void Page_Unload(object sender, EventArgs e)
{
this._reportDocument.Dispose();
}
}
}
方法2
using System;
using System.Linq;
using CrystalDecisions.Shared;
using System.Configuration;
using System.Web.Configuration;
using CrystalDecisions.CrystalReports.Engine;
using WebReports.Models.Helpers.CrystalReports; //Reference to CR wrapper
namespace YourNamespace
{
public partial class ReportForm : System.Web.UI.Page
{
protected string _serverName;
protected string _databaseName;
protected string _schemaName;
protected string _userId;
protected string _userPassword;
protected bool _integratedSecurity;
protected string _databaseType;
/// <summary>
/// Load report
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Init(object sender, EventArgs e)
{
CReportParameter reportParameter;
//These settings should be initialized from i.e. web.config in Page_PreInit
if (!IsPostBack)
{
if (this._databaseType == CReportDatabaseType.ORACLE.ToString())
{
//static wrapper class
CReportDocumentManager.ServerName = this._serverName;
CReportDocumentManager.DatabaseName = String.Empty;
CReportDocumentManager.SchemaName = this._schemaName;
CReportDocumentManager.DatabaseType = CReportDatabaseType.ORACLE;
CReportDocumentManager.UserId = this._userId;
CReportDocumentManager.UserPassword = this._userPassword;
CReportDocumentManager.IntegratedSecurity = false;
//Get report name from query string. Define Your own method to get report name
var parReportName = Request.QueryString["reportname"];
if (String.IsNullOrEmpty(parReportName))
{
lblConfigError.Text = "Crystal Report name is not being provided.";
return;
}
//get par1. Your own method to provide report parameters. This is from MVC application
var par1 = RouteData.Values["par1"];
//get par2
var par2 = RouteData.Values["par2"];
if (par1 == null || par2 == null)
{
lblConfigError.Text = "Crystal Report parameters are not being provided.";
return;
}
reportParameter = new CReportParameter();
reportParameter.ParameterName = "@parYear";
reportParameter.ParameterValue = par1;
reportParameter.CReportParameterValueKind = ParameterValueKind.StringParameter;
CReportDocumentManager.AddCReportParameter(reportParameter);
reportParameter = new CReportParameter();
reportParameter.ParameterName = "@parCityCode";
reportParameter.ParameterValue = par2;
reportParameter.CReportParameterValueKind = ParameterValueKind.StringParameter;
CReportDocumentManager.AddCReportParameter(reportParameter);
CReportDocumentManager.ReportFile = Server.MapPath("~/ReportFiles/") + parReportName;
ReportDocument doc = CReportDocumentManager.GetCReportDocument();
crViewer.ReportSource = doc;
Session[parReportName] = doc;
}
}
else
{
var parReportName = Request.QueryString["reportname"];
ReportDocument doc = (ReportDocument)Session[parReportName];
crViewer.ReportSource = doc;
}
}
}
}
安置自己的ReportViewer代码隐藏获得有益的帮助! – 2013-10-15 13:11:11