ASp.NET MVC+CrystalReportViewer+ веб-формы
У меня есть CrystalReportViewer в веб-форме, и я загружаю отчет динамически, передавая параметры. Все эти данные находятся в методе Page_Load. Работает нормально и отчет загружается. Но при нажатии "Следующая страница" средство просмотра отчетов не перемещается мимо страницы 2. Похоже, что отчет загружается при нажатии кнопки "Следующая страница" и устанавливается текущая страница средства просмотра. Мой код ниже:
protected void Page_Load(object sender, EventArgs e)
{
//if (!Page.IsPostBack)
{
string reportPath = Request.QueryString["ReportName"];
string parameters = Request.QueryString["Parameters"];
LoadReport(reportPath, parameters);
}
}
private void LoadReport(string ReportPath, string RptParams)
{
CrystalDecisions.Shared.TableLogOnInfo ConInfo = new CrystalDecisions.Shared.TableLogOnInfo();
ParameterValues crParameterValues;
ParameterDiscreteValue crParameterDiscreteValue;
ParameterFieldDefinitions crParameterFieldDefinitions;
ParameterFieldDefinition crParameterFieldDefinition;
string[] strParValPair;
string[] strVal;
int index;
String paramInfoMsg = "";
int TableCounter;
String ReportName = ReportPath.Substring(ReportPath.LastIndexOf("/") + 1);
try
{
string relPath = Server.MapPath(ReportPath);
objReport.Load(relPath);
crParameterFieldDefinitions = objReport.DataDefinition.ParameterFields;
//Set the connection information to ConInfo object so that we can apply the
//connection information on each table in the report
ConInfo.ConnectionInfo.UserID = System.Configuration.ConfigurationManager.AppSettings["UserID"];
ConInfo.ConnectionInfo.Password = System.Configuration.ConfigurationManager.AppSettings["Password"];
ConInfo.ConnectionInfo.ServerName = System.Configuration.ConfigurationManager.AppSettings["ServerName"];
ConInfo.ConnectionInfo.DatabaseName = System.Configuration.ConfigurationManager.AppSettings["DatabaseName"];
String RootReportSPLocation = ConInfo.ConnectionInfo.DatabaseName + "." + ConInfo.ConnectionInfo.UserID + ".";
for (TableCounter = 0; TableCounter < objReport.Database.Tables.Count; TableCounter++)
{
objReport.Database.Tables[TableCounter].ApplyLogOnInfo(ConInfo);
try
{
if (objReport.Database.Tables[TableCounter].Location.Trim() == "") // only fall back on this code if the Location doesn't already exist
if (objReport.Database.Tables[TableCounter].TestConnectivity()) // comment out this block should Report Running cause app crashes again, with any luck the above IF statement resolved them
objReport.Database.Tables[TableCounter].Location = ConInfo.ConnectionInfo.DatabaseName + "." + ConInfo.ConnectionInfo.UserID + "." + objReport.Database.Tables[TableCounter].Location.Substring(objReport.Database.Tables[TableCounter].Location.LastIndexOf(".") + 1); //RootReportSPLocation + objReport.Database.Tables[TableCounter].Location.Substring(objReport.Database.Tables[TableCounter].Location.LastIndexOf(".") + 1);
} // From what was experienced even with the Try/Catch present an Informix DLL (iclit09b.dll) is crashing which occurs outside our scope so it CAN'T be caught
catch (Exception) { }
}
//set the crSections object to the current report's sections
Sections crSections = objReport.ReportDefinition.Sections;
//loop through all the sections to find all the report objects
foreach (Section crSection in crSections)
{
ReportObjects crReportObjects = crSection.ReportObjects;
//loop through all the report objects to find all the subreports
foreach (ReportObject crReportObject in crReportObjects)
{
if (crReportObject.Kind == ReportObjectKind.SubreportObject)
{
// You will need to typecast the reportobject to a subreport object once you find it
SubreportObject crSubreportObject = (SubreportObject)crReportObject;
// Open the subreport object
ReportDocument crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);
for (TableCounter = 0; TableCounter < crSubreportDocument.Database.Tables.Count; TableCounter++)
{
crSubreportDocument.Database.Tables[TableCounter].ApplyLogOnInfo(ConInfo);
// The main report seems to work without this so we might consider removing it here or put an additional check to see if it is necessary
crSubreportDocument.Database.Tables[TableCounter].Location = RootReportSPLocation + crSubreportDocument.Database.Tables[TableCounter].Location.Substring(crSubreportDocument.Database.Tables[TableCounter].Location.LastIndexOf(".") + 1);
}
}
}
}
// Apply passed in values to their matching parameters
if ((TableCounter > 0) && (RptParams.Trim() != ""))
{
//strParValPair = RptParams.Split('&');
strParValPair = RptParams.Split('@');
for (index = 0; index < strParValPair.Length; index++)
{
if (strParValPair[index].Contains("=") == true)
{
strVal = strParValPair[index].Split('=');
try
{
crParameterFieldDefinition = crParameterFieldDefinitions[strVal[0]];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Clear();
crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = strVal[1];
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
}
catch { paramInfoMsg += strVal[0] + " (" + strVal[1] + ")\n"; } // Debug data gathering
}
}
}
CrystalReportViewer1.ReportSource = objReport;
CrystalReportViewer1.DataBind();
}
catch (Exception)
{
LoadFailed = true;
}
}
Эта проблема не является CrystalReportViewer. Любая помощь приветствуется.