c# - Accessing a property inside a property -


i curently have set below

public class proptsclass {     public class classa      {         public list<classb> pcb { get; set; }     }      public class classb     {         public list<classc> pcc { get; set; }     }      public class classc     {          public string _someproperty { get; set; }     } } 

what want databind object classa listview 1 of columns being databound classc._someproperty . when try databind <%#eval("namespace.proptsclass.classa.pcb.pcc._someproperty") %> error: "databinding: namespace proptsclass.classa + classb' not contain property name '_someproperty'".

can tell me doing wrong , correct way of doing it. secondly there better way can achieve same in code behind instead of asp.net. in advance

databind on listviews , gridviews "shallow" search property/field names bind columns. also, not "flatten" list of lists have in structure. if want bind multilevel object model, need either expose child property on parent via "pass-through" property, or project values want display one-dimensional collection of "view-helper" class. choose latter in case, since want value of element accessed multi-dimensionally.

try this:

var displayresult = theproptsclass.a.pcb.selectmany(b=>b.pcc).select(c._someproperty); 

the selectmany() function acts "flatten" relationship between classb , classc, , combined select() return _someproperty values of cs in bs in 1 a. can chain selectmany() call if have collection of need project flat collection of bs.


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -