2012-03-13 112 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; 
相關問題