2012-03-13 119 views
1

有人能请我帮忙吗?jqgrid作为数据源的对象列表(带有子对象)

我有2个班,Foo和武

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() 
    { 
    } 
} 

我有FOOS名单现在

List<Foo> foolist 

我可以为我的jqGrid一个数据源。做列价格和代码,但我不能使用子场

我希望能够做这样的事

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

什么想法? 谢谢!

+0

没有你设法让这种随时随地。我受到同样的问题,并在这里发布了一个例子:http://stackoverflow.com/questions/9958084/null-reference-binding-jqgrid-to-object-that-c​​ontains-sub-objects。 – 2012-03-31 17:31:43

回答

0

基本上,您可以更改您的退货清单。你创建一个新的对象。例如:InfoFoo。您在使用Foo和Moo类时设置了它的属性。然后返回这个类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; } 
} 

设置InfoFoo性质,

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; 
相关问题