PC Review


Reply
Thread Tools Rating: Thread Rating: 3 votes, 1.00 average.

display second level attribute in grid control

 
 
eddiec
Guest
Posts: n/a
 
      23rd Apr 2009
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 :-)
 
Reply With Quote
 
 
 
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      23rd Apr 2009
Ed,

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

Cor


"eddiec" <(E-Mail Removed)> 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 :-)


 
Reply With Quote
 
eddiec
Guest
Posts: n/a
 
      24th Apr 2009
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 :-)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Grid View Add Attribute Not on Headers bdog4@hotmail.com Microsoft ASP .NET 1 29th Apr 2007 09:25 AM
Need high level text display control ... Paul_Madden via DotNetMonster.com Microsoft C# .NET 0 14th Oct 2006 09:37 PM
How to add an attribute at table level using GridView =?Utf-8?B?TGkgUGFuZw==?= Microsoft ASP .NET 2 27th Mar 2006 02:57 PM
Injecting a variable attribute from a select grid control Thaddius39 Microsoft ASP .NET 0 20th Nov 2005 04:27 AM
Capture date from calendar control and display in grid .. Nikkie Microsoft ASP .NET 0 22nd Nov 2004 12:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:15 PM.