我试图让嵌套的对象在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