水晶报表查看器问题..? [英] Crystal Report Viewer Problem..?
问题描述
我已经使用C#作为后端在ASP.NET中创建了一个项目.
在我的项目中,我使用了水晶报表来向用户显示报表.
我有动态报告,例如用户选择1个报告,然后Crystal Report Viewer显示第一个报告,或者选择第二个,然后Crystal Report Viewer显示第二个报告.
并且我还通过设置Crystal报表查看器的paramterfiledinfo属性将参数值传递给了我的报表.
现在我已经做到了,它将很好用.但是当我在报表中有多于一页的数据并且我转到第二页时会出现这样的错误..
没有有效的报告来源"
请帮助我...
I have created a Project in ASP.NET using C# as Back End.
In my project i have use crystal report to show reports to user.
I have dynamic report like when user select 1 report then the Crystal Report Viewer Show the First Report or it select second then the crystal report viewer show the second report.
and i have also pass the parameter value to my report by seting crystal report viewers paramterfiledinfo property.
now i have done it and it will work great. but my problem is arise when i have more then one page data in report and i went to second page it will show error like this..
"No valid report source is available"
please help me...
推荐答案
我认为您需要在每次报表查看器页面回发时将数据绑定到报表,如下所示:
I think you need to bind the data to the report every time the Report viewer page postback, as following:
CrystalDecisions.CrystalReports.Engine.ReportDocument rpt;
protected void Page_Load(object sender, EventArgs e)
{
rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
rpt.Load(Server.MapPath(GetFilePath(/*report file path*/)));
if (rptData is DataSet)
rpt.SetDataSource((DataSet)rptData);
else if (rptData is DataTable)
rpt.SetDataSource((DataTable)rptData);
else if (rptData is IEnumerable)
rpt.SetDataSource((IEnumerable)rptData);
CrystalReportViewer1.ReportSource = rpt;
CrystalReportViewer1.DataBind();
}
并在每次页面卸载时关闭报告,如下所示:
and close the report every time the page unload, as following:
protected void Page_UnLoad(object sender, EventArgs e)
{
if (rpt != null)
{
rpt.Close();
rpt.Dispose();
}
}
要解决这个问题,我需要这样做....
在将报告设置为报告后,我将其添加到会话中并同时显示报告,并在侧面OnNavigate
或OnViewZoom
等中调用此函数....报告查看器的事件
Fro solving this issue i need to do like this....
after assinig a report to report viwer i will add it to session also displaying report and also call this function in sideOnNavigate
orOnViewZoom
etc.... events of report viewer
protected void setReportSource(object sender, EventArgs e)
{
if (Session["Report"] != null)
{
if (Session["Parameter"] != null)
{
CRPTViewer.ParameterFieldInfo = (ParameterFields)Session["Parameter"];
}
CRPTViewer.ReportSource = (ReportDocument)Session["Report"];
}
}
这篇关于水晶报表查看器问题..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!