On Apr 23, 6:14*pm, "Cor Ligthert[MVP]" <Notmyfirstn...@planet.nl>
wrote:
> Ed,
>
> Any reason that you don't use
> <asp:BoundField DataField="MyObject1.MyObject2.Name" HeaderText="Name" />
>
> Cor
>
> "eddiec" <edwardch...@gmail.com> wrote in message
>
> news:9aaa5f79-7d85-45bf-b550-(E-Mail Removed)...
>
>
>
> > Hi,
>
> > I have a grid view that is bound to a linq data source.
>
> > The data for the linq data source is bound to a linq array in the
> > Selecting event for the linq data source.
>
> > * * * *var MyObjectArray =
> > * * * * * * * * from o in context.MyObjects
> > * * * * * * * * where (o.ID.Equals(intID))
> > * * * * * * * * select o;
>
> > I can display simple attributes of the linq array in the data grid.
>
> > The problem is that the object type that is returned in the linq query
> > has as an attribute a second object type.
>
> > How can I display attributes of the second object type in the grid
> > view?
> > e.g. MyObject1.MyObject2.Name
>
> > I have tried Object2.Name in the grid:
> > <asp:BoundField DataField="Object2.Name" HeaderText="Name" />
> > but this results in an error:
> > "A field or property with the name 'Object2.Name' was not found on the
> > selected data source."
>
> > Any assistance would be much appreciated.
>
> > cheers,
>
> >eddiec:-)- Hide quoted text -
>
> - Show quoted text -
Hi Everyone,
Thank you for your help.
I tried the first method suggested;
class MyObject1
{
public MyObject2 MyObject2 { get; set; }
public string MyObject2Name { get { return
MyObject2.Name; } }
}
This worked fine
I tried the second method suggested:
<asp:BoundField DataField="MyObject1.MyObject2.Name"
HeaderText="Name" />
I could not get this to work, probably becuase the way I am binding
the gridview to the linq data source is by using the Selecting event
of the linq data source, so in the:
protected void ldsProjectPhases_Selecting(object sender,
LinqDataSourceSelectEventArgs e){}
method, I create a var anonymous type and then call
e.Result = myVar;
C# takes care of the rest
I do not think that by the time the linq data source gets back to the
grid view that the object representing the data to the grid view is
MyVar.
Hope that made sense
Cheers,
eddiec :-)
|