0
votes

I have two classes:

public class Contact{

     public string contact { get; set; }
     public string contact_type { get; set; }

 }

public class Person{

 public string first_name { get; set; }
 public string last_name { get; set; }
 Contact phone

}

In my asp.net application I need to see list of persons in a gridview. I use ObjectDataSource to bind List. But only two columns: first_name and last_name are presents in the gridview. It is important to see contact of person. In other words, how to bind subclass Contact to the same gridview. What is the best way to do this? I don't like idea to use DataTable. Thanks!

1
DO you want Contact fields to appear as separate columns in the grid view? - Andrei

1 Answers

1
votes

I think your best bet is to use template field and eval to access inner object fields:

<asp:TemplateField HeaderText="Contact">
    <ItemTemplate>
        <%# Eval("phone.contact") %>
    </ItemTemplate>
</asp:TemplateField>

If you are using auto generated columns feature, keep it, declared columns will be appended after generated ones.