PC Review


Reply
Thread Tools Rate Thread

Binding Objects

 
 
jerome.avoustin@gmail.com
Guest
Posts: n/a
 
      26th Feb 2008
Hi All !

I got some pbs with binding objects in ASP.Net 2.0
I've got such an object composition :

class Person
{
public string Name { get; set; }
public int Age { get; set; }
public Car Car { get; set; }
}

class Car
{
public string Type { get; set; }
public string Color { get; set; }
}

I build a List<Person> and try to bind it to a GridView
Here's my GridView :

<asp:GridView ID="gdvTest" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="Name" DataField="Name"/>
<asp:BoundField HeaderText="Age" DataField="Age"/>
</Columns>
</asp:GridView>

Then I try to bind values from the car
I try either this... :

<asp:BoundField HeaderText="Car Type" DataField="Car.Type"/>

.... Or this :

<asp:TemplateField HeaderText="Car Type">
<ItemTemplate>
<%# DataBinder.Eval(Container, "Car.Type") %>
Or
<%# DataBinder.Eval(Container,
"Personne.Car.Type") %>
</ItemTemplate>
</asp:TemplateField>

I always get an exception :

Impossible to find a fiels or a propertie 'Car.Type' in the datasource
or
DataBinding : 'System.Web.UI.WebControls.GridViewRow' has no propertie
calld 'Car'. (traduction from french)

Has someone any idea ?

Thanx !

 
Reply With Quote
 
 
 
 
jerome.avoustin@gmail.com
Guest
Posts: n/a
 
      27th Feb 2008

It's OK !!
I've found the error !

You must use :

<asp:TemplateField HeaderText="Car Type">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,
"Car.Type") %>
</ItemTemplate>
</asp:TemplateField>

I've forgotten .DataItem with Container !
But in the FRENCH documentation, it is said :

"For any of the list Web controls, such as DataGrid, DataList, or
Repeater, container should be Container.DataItem."

And nothing about GridView !
But in the english documentation, GridView is mentionned !

Allright... I'll always read english documentation next times !

Thanx
 
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
Re: Binding objects Frans Bouma [C# MVP] Microsoft C# .NET 1 14th Jan 2009 08:52 AM
Binding objects ? Jarod Microsoft ASP .NET 1 13th May 2006 08:41 PM
Binding to objects or db John Microsoft ADO .NET 2 12th Jul 2005 03:48 PM
binding to objects =?Utf-8?B?cnVmdXM=?= Microsoft Dot NET 1 28th Oct 2004 11:05 AM
Binding between objects =?Utf-8?B?QW50ZXJv?= Microsoft C# .NET 1 9th Jul 2004 05:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:54 AM.