我在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