C# 显示“错误”的本地RDLC报告,其中应显示报告参数
我正在使用RDLC VS2010在网页MVC3上将一个简单的装运标签呈现为PDF。我有一个参数需要传递给RDLC ShipmentId。我传递了该参数,并且报告正确呈现,除了应该显示我传递的参数的文本框 RDLC上的文本框的值设置为“=参数!”!ShipmentId.Value' 我的代码是这样的:C# 显示“错误”的本地RDLC报告,其中应显示报告参数,c#,reportviewer,rdlc,microsoft-reporting,C#,Reportviewer,Rdlc,Microsoft Reporting,我正在使用RDLC VS2010在网页MVC3上将一个简单的装运标签呈现为PDF。我有一个参数需要传递给RDLC ShipmentId。我传递了该参数,并且报告正确呈现,除了应该显示我传递的参数的文本框 RDLC上的文本框的值设置为“=参数!”!ShipmentId.Value' 我的代码是这样的: shipment.ShipmentId = "123TEST"; Warning[] warnings; string mimeType; string[] str
shipment.ShipmentId = "123TEST";
Warning[] warnings;
string mimeType;
string[] streamids;
string encoding;
string filenameExtension;
LocalReport report = new LocalReport();
report.ReportPath = @"Labels\ShippingLabel.rdlc";
report.Refresh();
report.EnableExternalImages = true;
ReportParameter param = new ReportParameter("ShipmentId", shipment.ShipmentId, true);
report.SetParameters(param);
report.Refresh();
byte[] bytes = report.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
return new FileContentResult(bytes, mimeType);
问题是ReportViewer在使用ProcessingMode.Local时不能有ReportParameters。相反,我将代码改为使用数据源而不是参数
Warning[] warnings;
string mimeType;
string[] streamids;
string encoding;
string filenameExtension;
var viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = @"Labels\ShippingLabel.rdlc";
viewer.LocalReport.EnableExternalImages = true;
var shipLabel = new ShippingLabel { ShipmentId = shipment.ShipmentId, Barcode = GetBarcode(shipment.ShipmentId) };
viewer.LocalReport.DataSources.Add(new ReportDataSource("ShippingLabel", new List<ShippingLabel> { shipLabel }));
viewer.LocalReport.Refresh();
var bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);