code_junkie

Microsoft reports nested object datasource gives #Error

Nov 13th, 2011
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. =Fields!Name.Value.FirstName
  2.  
  3. namespace ReportTest
  4. {
  5.  
  6. public class ClientItem
  7. {
  8. public int Id { get; set; }
  9. public ClientName Name { get; set; }
  10. }
  11.  
  12. public class ClientName
  13. {
  14. public ClientName(string first, string last)
  15. {
  16. FirstName = first;
  17. LastName = last;
  18. }
  19.  
  20. string FirstName { get; set; }
  21. string LastName { get; set; }
  22. }
  23.  
  24. public partial class Form1 : Form
  25. {
  26. private List<ClientItem> clients = new List<ClientItem>();
  27.  
  28. public Form1()
  29. {
  30. InitializeComponent();
  31. PopulateLists();
  32. GenerateReport();
  33. }
  34.  
  35. private void PopulateLists()
  36. {
  37. clients.Add(new ClientItem { Id = 1, Name = new ClientName("Adrian", "Adesco") } );
  38. clients.Add(new ClientItem { Id = 2, Name = new ClientName("Brian", "Briar") } );
  39. clients.Add(new ClientItem { Id = 3, Name = new ClientName("Clive", "Cussler") } );
  40. }
  41.  
  42. private void GenerateReport()
  43. {
  44. this.Text = "Report Control Demo";
  45. this.ClientSize = new System.Drawing.Size(950, 600);
  46.  
  47. ReportViewer reportViewer = new ReportViewer();
  48.  
  49. reportViewer.ProcessingMode = ProcessingMode.Local;
  50.  
  51. reportViewer.LocalReport.ReportPath = "TestReport.rdlc";
  52.  
  53. reportViewer.LocalReport.DataSources.Add(new ReportDataSource("ReportTest_ClientItem", clients));
  54.  
  55. reportViewer.Dock = DockStyle.Fill;
  56. this.Controls.Add(reportViewer);
  57.  
  58. reportViewer.RefreshReport();
  59. }
  60. }
  61. }
  62.  
  63. public class ClientName
  64. {
  65. public ClientName(string first, string last)
  66. {
  67. FirstName = first;
  68. LastName = last;
  69. }
  70.  
  71. public string FirstName { get; set; }
  72. public string LastName { get; set; }
  73. }
  74.  
  75. [assembly: AllowPartiallyTrustedCallers]
Add Comment
Please, Sign In to add comment