我試圖讓嵌套的對象在Microsoft報告中工作。我從http://www.gotreportviewer.com/objectdatasources/index.html下載了示例代碼,並且它運行正常。微軟報告嵌套對象數據源給出#Error
我建立了一個基於Windows窗體和他們的代碼,以及所有在下面的小應用程序時,我引用一個嵌套的對象值是「#錯誤」在數據應該出現的地方,我曾經得到。
在報告中,我使用的建議在網站的同一嵌套對象語法:
=Fields!Name.Value.FirstName
它適用於他們在我的電腦上的應用程序,而不是我的。我無法理解它!有沒有人遇到過這種情況,或知道爲什麼會發生這種情況
而且 - 我不知道這是有關 - 我不能給LocalReport.DataSources對象添加ClientItem的單個實例。它必須是一個列表。但是,在呈現時,它只會在報表的表格中顯示一行(#Errored)數據。
任何幫助,將不勝感激!
namespace ReportTest
{
public class ClientItem
{
public int Id { get; set; }
public ClientName Name { get; set; }
}
public class ClientName
{
public ClientName(string first, string last)
{
FirstName = first;
LastName = last;
}
string FirstName { get; set; }
string LastName { get; set; }
}
public partial class Form1 : Form
{
private List<ClientItem> clients = new List<ClientItem>();
public Form1()
{
InitializeComponent();
PopulateLists();
GenerateReport();
}
private void PopulateLists()
{
clients.Add(new ClientItem { Id = 1, Name = new ClientName("Adrian", "Adesco") });
clients.Add(new ClientItem { Id = 2, Name = new ClientName("Brian", "Briar") });
clients.Add(new ClientItem { Id = 3, Name = new ClientName("Clive", "Cussler") });
}
private void GenerateReport()
{
this.Text = "Report Control Demo";
this.ClientSize = new System.Drawing.Size(950, 600);
ReportViewer reportViewer = new ReportViewer();
reportViewer.ProcessingMode = ProcessingMode.Local;
reportViewer.LocalReport.ReportPath = "TestReport.rdlc";
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("ReportTest_ClientItem", clients));
reportViewer.Dock = DockStyle.Fill;
this.Controls.Add(reportViewer);
reportViewer.RefreshReport();
}
}
}
我有一個非常類似的問題給你,但加入'AllowPartiallyTrustedCallers`並沒有爲我工作。你對這個問題有什麼其他建議嗎? – meanbunny 2013-01-31 18:33:42