I think there are some controls that let you do this, but I've
typically done it one of three ways:
1) Create a container object that exposes a property that you need,
and use a collection of containers as your data source. For example:
class Foo {
public Bar MyBar { get; set; }
}
class Bar {
public string MyString { get; set; }
}
class Container {
private Foo _foo;
public string MyString { get { return _foo.MyBar.MyString; } }
}
2) Same idea as #1, except extend the original object to include the
property.
class FooEx : Foo {
public string MyString { get { return MyBar.MyString; } }
}
3) Use a TemplateField instead of a BoundField in your grid. You can
use inline code to cast the data item as the appropriate type, and
retrieve the value that way. I believe the syntax is something like
the following:
<asp:TemplateField>
<%# ((Foo)Container.DataItem).MyBar.MyString #>
</asp:TemplateField>
All three of these methods will get you what you need, but it's just a
matter of figuring out which is the easiest or most practical to
implement in your scenario.
On Apr 22, 11:23 pm, eddiec <[email protected]> wrote:
> There is a slight mistake in the query above:
> "The problem is that the object type that is returned in the linq
> query contains an array of other objects."
>
> The first object type does not contain an array of the second object
> type, it contains a single instance of the second object type
>
> I am trying to display the following attribute:
> MyObject1.MyObject2.Name