display second level attribute in grid control

E

eddiec

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 :)
 
C

Cor Ligthert[MVP]

Ed,

Any reason that you don't use
<asp:BoundField DataField="MyObject1.MyObject2.Name" HeaderText="Name" />

Cor
 
E

eddiec

Ed,

Any reason that you don't use
<asp:BoundField DataField="MyObject1.MyObject2.Name" HeaderText="Name" />

Cor














- 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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top