I am using an RDLC (VS2010) to render a simple shipping label to PDF on a web page (MVC3). I have a single parameter I need to pass to the RDLC (ShipmentId). I pass that parameter and the report renders correctly except for the textbox that is supposed to display the parameter I pass in.
The textbox on the RDLC has its value set to '=Parameters!ShipmentId.Value'.
Here's what my code looks like:
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);
The problem turned out to be that ReportViewer cannot have ReportParameters when using ProcessingMode.Local. Instead I changed my code to use a datasource instead of paramters.
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);