Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
65
Binding custom objects
posted

Hi,

I have these objects:

public class Cars

{

public String Name { get; set; }

public String Make { get; set; }

public Manufacturer Manufacturer { get; set; }

}

public class Manufacturer

{

public String Name { get; set; }

public String Address { get; set; }

public String Telephone { get; set; }public String City { get; set; }

}

I'm using a List<Cars> with an ObjectDataProvider to bind data to the grid. The question is how to show Manufacturers properties in the Grid (for example Manufacturers Addres). If I use the following code it doesn't work:

 <igDP:FieldLayout.Fields>
 <igDP:Field Name="Name" Label="Car Name">
 <igDP:Field Name="Make" Label="Car Make">
 <igDP:Field Name="Manufacturer.Name" Label="Manufacturer Name">
 <igDP:Field Name="Manufacturer.Address" Label="Manufacturer Address">
 <igDP:Field Name="Manufacturer.City" Label="Manufacturer City">
</igDP:FieldLayout.Fields>

How could I bind custom object properties to fields? 

Thanks

Juan Puebla

  • 415
    Verified Answer
    posted

    Hi,

    In order to display a nested/complex property, you have to add UnboundField objects and set their BindingPath and BindingMode properties. For an example, click the links below:

    An example in XAML

    An example in C#/VB.NET

    In your particular case, the following field definitions should work:

     <igDP:FieldLayout.Fields>
     <igDP:Field Name="Name" Label="Car Name">
     <igDP:Field Name="Make" Label="Car Make">
     <igDP:UnboundField Name="ManufacturerName" BindingPath="Manufacturer.Name" BindingMode="TwoWay" Label="Manufacturer Name">
     <igDP:UnboundField Name="ManufacturerAddress" BindingPath="Manufacturer.Address" BindingMode="TwoWay" Label="Manufacturer Address">
     <igDP:UnboundField Name="ManufacturerCity" BindingPath="Manufacturer.City" BindingMode="TwoWay" Label="Manufacturer City">
    </igDP:FieldLayout.Fields>