Я создаю небольшое приложение в Visual Studio 2010 с .Net 4.0 и C #, где я генерирую ReportViewer-отчет из списка.Затем в моем tablix есть подотчет, который должен передать значение свойства из WebLink с именем ProviderIdentifier.Я реализую событие SubReportProcessing в своем отчете, чтобы вернуть данные во вложенный отчет следующим образом:
private void localReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
List<WebLink> links = LinkProvider.FetchSublinks(LinkProvider.Fetch(new WebLink(new Uri("http://www.contentstudio.se/"))));
e.DataSources.Add(new ReportDataSource("ParentLinks", links));
}
В настоящее время я возвращаю одинаковые ссылки для всех экземпляров вложенного отчета.Отчет работает нормально, пока я не попытаюсь передать параметр в подотчет.Когда я добавляю параметр с помощью ProviderIdentifier (который я могу отобразить в своем отчете без проблем), я всегда получаю исключение NullReferenceException с сообщением «Ссылка на объект не установлена для экземпляра объекта».когда я вызываю Render () для моего LocalReport-объекта.То же самое происходит, если я добавляю статическое значение (например, 1) в отчет вместо передачи ProviderIdentifier.Если я удаляю параметр все вместе, он прекрасно работает, но у меня нет способа определить, какие ссылки возвращать в подотчет.
Кто-нибудь знает, что может вызвать эту проблему?
Полный код:
public void RenderReport()
{
LocalReport localReport = new LocalReport
{
ReportPath = ("BrokenLink.rdlc"),
EnableHyperlinks = true,
ShowDetailedSubreportMessages = true
};
List<WebLink> links = LinkProvider.FetchSublinks(LinkProvider.Fetch(new WebLink(new Uri("http://www.contentstudio.se/"))));
ReportDataSource reportDataSource = new ReportDataSource("Weblinks", links);
localReport.DataSources.Add(reportDataSource);
localReport.SubreportProcessing += localReport_SubreportProcessing;
const string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
//The DeviceInfo settings should be changed based on the reportType
//http://msdn2.microsoft.com/en-us/library/ms155397.aspx
const string deviceInfo = "<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.5in</MarginTop>" +
" <MarginLeft>1in</MarginLeft>" +
" <MarginRight>1in</MarginRight>" +
" <MarginBottom>0.5in</MarginBottom>" +
" <DpiX>72</DpiX>" +
" <DpiY>72</DpiY>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
//Render the report
byte[] renderedBytes = localReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
File.WriteAllBytes("I:\\report.pdf", renderedBytes);
}