C# 在循环中显示多个Crystal报告
我在复选框列表中有多个Crystal报告,因此用户可以同时打印/显示多个报告 目前,我正在使用会话传递reportdocument,但大多数情况下,会话值在分配给crystal report之前会被替换,因此多个报表包含相同的数据。我在每个循环上应用了3秒延迟,但不是可靠的解决方案。并且图像也不会显示在报告中 有什么优雅的技巧可以做到这一点吗 或 会话变量的替代方案是什么 Jquery:C# 在循环中显示多个Crystal报告,c#,asp.net-mvc,crystal-reports-2010,C#,Asp.net Mvc,Crystal Reports 2010,我在复选框列表中有多个Crystal报告,因此用户可以同时打印/显示多个报告 目前,我正在使用会话传递reportdocument,但大多数情况下,会话值在分配给crystal report之前会被替换,因此多个报表包含相同的数据。我在每个循环上应用了3秒延迟,但不是可靠的解决方案。并且图像也不会显示在报告中 有什么优雅的技巧可以做到这一点吗 或 会话变量的替代方案是什么 Jquery: $.each(chkBoxarr, function (index, value) { var w = w
$.each(chkBoxarr, function (index, value) {
var w = window.open();
$.ajax({
type: "POST",
url: "PrintReports",
traditional: true,
data: { id: value},
datatype: "json",
success: function (data) {
w.document.write(data);
},
error: function () {
alert("Error");
}
});
});
控制器:
public ActionResult PrintReports(id)
{
ReportDocument rpt = new ReportDocument();
rpt.Load("~/ReportFileName.rpt");
HttpContext.Session["rpt"] = rpt;
return Redirect("~/Viewer.aspx");
}
Viewer.aspx.cs
Page_Init(object sender, EventArgs e)
{
var rpt = System.Web.HttpContext.Current.Session["rpt"];
CrystalReportViewer1.ReportSource = (ReportDocument)rpt;
}
Javascript:
$.each(chkBoxarr, function (index, value) {
$.ajax({
url: "PrintReports",
type: 'GET',
data: { id: value},
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (data) {
if (data.success) {
var URL = 'Viewer.aspx?type=' + data.URL;
window.open(URL);
}
else {
alert(data.message);
}
}
});
});
public ActionResult PrintReports(id)
{
ReportDocument rpt = new ReportDocument();
rpt.Load("~/ReportFileName.rpt");
string guid = Guid.NewGuid().ToString();
Session[guid] = rpt;
return Json(new { success = true, URL = guid }, JsonRequestBehavior.AllowGet);
}
$.each(chkBoxarr, function (index, value) {
var URL = 'Viewer.aspx?id=' + value;
window.open(URL);
});
protected void Page_Load(object sender, EventArgs e)
{
ReportDocument rpt = new ReportDocument();
rpt.Load("~/ReportFileName.rpt");
CrystalReportViewer1.ReportSource = rpt;
}
控制器:
$.each(chkBoxarr, function (index, value) {
$.ajax({
url: "PrintReports",
type: 'GET',
data: { id: value},
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (data) {
if (data.success) {
var URL = 'Viewer.aspx?type=' + data.URL;
window.open(URL);
}
else {
alert(data.message);
}
}
});
});
public ActionResult PrintReports(id)
{
ReportDocument rpt = new ReportDocument();
rpt.Load("~/ReportFileName.rpt");
string guid = Guid.NewGuid().ToString();
Session[guid] = rpt;
return Json(new { success = true, URL = guid }, JsonRequestBehavior.AllowGet);
}
$.each(chkBoxarr, function (index, value) {
var URL = 'Viewer.aspx?id=' + value;
window.open(URL);
});
protected void Page_Load(object sender, EventArgs e)
{
ReportDocument rpt = new ReportDocument();
rpt.Load("~/ReportFileName.rpt");
CrystalReportViewer1.ReportSource = rpt;
}
Viewer.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
ReportName = Request.QueryString["type"].ToString();
ReportDocument doc = new ReportDocument();
doc = (ReportDocument)Session[ReportName];
if (doc == null)
Response.Write("<H2>Nothing Found; No Report name found</H2>");
CrystalReportViewer1.ReportSource = doc;
}
要显示图像,请将aspx文件CrystalImageHandler.aspx添加到存在Viewer.aspx的文件夹中。
还加
<httpHandlers>
<add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
</httpHandlers>
在Weconfig中。。。版本号因您的crystalreport版本而异谢谢您的建议;如果你的水晶报告中有多个页面,有没有不使用sessions的方法;每次单击“上一页”或“下一页”时,都会触发服务器端。您能否详细说明如何在没有会话的情况下使用并发多个报告来实现这一点(只需在您的答案中添加一些描述,而不仅仅是代码;这将非常有帮助)