I am currently using the RadGrid and have been differentiating my business objects by properties set in tables.
Example: One Table called 'Contacts' which has a flag column called 'IsPerson' which determines whether the contact is a Person or Company. When binding to the grid I would show or hide columns ( Visible='<%# Eval("IsPerson") %> ) applicable to either type based on whether the 'IsPerson' is true or false, but still have both Persons and Companies in the same bindable collection.
Look at the Code below to understand where I'm coming from:
However I have moved onto the entity framework and have implemented Table-Per-Hierarchy inheritance set out as follows:
To bind I would call
How do I differentiate between Person and Company objects in my collection when binding in a Custom GridTemplateColumn?
Example
<itemTemplate>
<%# Eval("Salary") %> // Works for type 'Person', NOT for type 'Company'
</ItemTemplate>
Please let me know if this doesn't make sense and I'll try and clarify further,,,,
Example: One Table called 'Contacts' which has a flag column called 'IsPerson' which determines whether the contact is a Person or Company. When binding to the grid I would show or hide columns ( Visible='<%# Eval("IsPerson") %> ) applicable to either type based on whether the 'IsPerson' is true or false, but still have both Persons and Companies in the same bindable collection.
Look at the Code below to understand where I'm coming from:
However I have moved onto the entity framework and have implemented Table-Per-Hierarchy inheritance set out as follows:
| abstract class Contact{ | |
| int ContactID; | |
| string Name; | |
| ....... | |
| } | |
| class Person : Contact{ | |
| decimal Salary; | |
| ....... | |
| } | |
| class Company : Contact{ | |
| decimal ShareValue; | |
| ....... | |
| } |
To bind I would call
| using (MyEntityContext c = new MyEntityContext()){ | |
| IList<Contacts> contacts = c.Contacts.ToList<Contacts>(); | |
| MyRadGrid.DataSource = contacts; | |
| MyRadGrid.DataBind(); | |
| } | |
How do I differentiate between Person and Company objects in my collection when binding in a Custom GridTemplateColumn?
Example
<itemTemplate>
<%# Eval("Salary") %> // Works for type 'Person', NOT for type 'Company'
</ItemTemplate>
Please let me know if this doesn't make sense and I'll try and clarify further,,,,