Reputation: 323
How to Show child property value in RDLC Report? for Example:
public class Person
{
public Address Address { get; set; }
}
public class Address
{
public string streetName {get;set;}
}
How to display streetName value in RDLC Report?
Upvotes: 0
Views: 2854
Reputation: 323
For All Properties we have to set [Serializable()] in Class
[Serializable()]
public class Person
{
public Address Address { get; set; }
}
[Serializable()]
public class Address
{
public string streetName {get;set;}
public SubAddress SubAddress{get;set;}
}
[Serializable()]
public class SubAddress
{
public string DoorNo {get;set;}
}
In Report in the code tab of report Properties follwing code is used
Public Function GetName(ByRef obj As Object) As String
If obj Is Nothing Then Return "na"
Else : Return obj.streetName
End If
End Function
and report field get it as =Code.GetName(Fields!Address.Value)
Upvotes: 0
Reputation: 2731
As you can read in this blog's post from Brian Hartman, there was a change since VS2010 for the nested class in a LocalReport.
He suggest to add the attribute [Serializable()] (if applicable).
Your class will be look like this:
[Serializable()]
public class Person
{
public Address Address { get; set; }
}
[Serializable()]
public class Address
{
public string streetName {get;set;}
}
Edit: added the code after some comments. Try to implement your class like this:
[Serializable()]
public class Person
{
private Address _address;
public Address Address
{
get
{
if(_address == null)
return new Address(string.Empty);
return _address;
}
set
{
_address = value;
}
}
[Serializable()]
public class Address
{
private string _streetName;
public string streetName
{
get
{
return _streetName;
}
set
{
_streetName = value;
}
}
public Address(string streetName)
{
_streetName = streetName;
}
}
}
In this way it will always return a value and never null.
Upvotes: 1