1

Can someone give me a hand with this please.

i have 2 classes, Foo and Moo

public class Foo
{
    public int Id { get; set; }
    public int price { get; set; }
    public String code { get; set; }
     public Moo moo { get; set; }

public Foo()
{
}
 }


 public class MOO
 {
     public int Id { get; set; }
     public String firstname { get; set; }
     public String surname { get; set; }

     public MOO()
     {
     }
 }

I have a list of FOOs now

List<Foo> foolist

I can make it a datasource for my jqgrid. and do columns for price and code, but I cant use the sub fields

I would love to be able to do something like this

<trirand:JQGridColumn DataField="moo.firstname" Searchable="true" /> 

any ideas? Thanks!

Oleg
  • 220,925
  • 34
  • 403
  • 798
Crudler
  • 2,194
  • 3
  • 30
  • 57
  • did you manage to get anywhere with this. I am suffering with the same problem and have posted an example here: http://stackoverflow.com/questions/9958084/null-reference-binding-jqgrid-to-object-that-contains-sub-objects. – chrisp_68 Mar 31 '12 at 17:31

1 Answers1

0

Basically, you can change your return list. You create a new object. Example: InfoFoo. you set its property while using Foo and Moo classes. Then return this class, List.

public class InfoFoo
{
  public int Id { get; set; }
  public int price { get; set; }
  public String code { get; set; }
  public int MooId { get; set; }
  public String MooFirstname { get; set; }
  public String MooSurname { get; set; }
}

for setting InfoFoo properties,

List<InfoFoo> ListInfoFoo=new List<InfoFoo>(); 
foreach(var foo in List<Foo>)
 {
   var infoFoo=new InfoFoo();
   infoFoo.Id=foo.Id;
   infoFoo.Price=foo.Price;
   infoFoo.code=foo.code;
   infoFoo.MooId=foo.Moo.Id;
   infoFoo.MooFirstName=foo.Moo.firstName;
   infoFoo.MooSurname=foo.Moo.surname;  
   ListInfoFoo.Add(infoFoo);
  }

 return ListInfoFoo;