C
Chitty
Hi All,
Hope someone can help me out on this one, it's been driving me around
the bend.
In essence I'm trying to replicate a custom class hierachy relating to
my problem domain database. The actual domain I'm working on is
irrelevant, so I've been playing with two noddy classes; Person and Pet
(the full code can be found here:
<http://www.junge.f9.co.uk/code/CustomClassDDL.zip>).
The notion is a Person has a Pet, so the Pet is a property of the
Person object. However when I try and use this relationship against a
DropDownList I can't figure out how to get it to work, as in:
Pet moDino = new Pet(1, "Dino", 4);
Person moFranz = new Person(99, "Mr", "Flintstone", moDino);
ArrayList marrPeople = new ArrayList();
marrPeople.Add(moFranz);
ddlPeople.DataValueField = "Id";
ddlPeople.DataTextField = "MyPet.Name";
ddlPeople.DataSource = marrPeople;
ddlPeople.DataBind();
I've also tried variations like:
ddlPeople.DataTextField = "((Pet) MyPet).Name";
but still didn't get anywhere
I just get the error "DataBinder.Eval: 'Person' does not contain a
property with the name MyPet.Name."
However I know I can do this in a datagrid by casting in the
DataBinder.Eval in the HTML view, but can't figure the equivalent for
the code behind
Any help much appreciated
Hope someone can help me out on this one, it's been driving me around
the bend.
In essence I'm trying to replicate a custom class hierachy relating to
my problem domain database. The actual domain I'm working on is
irrelevant, so I've been playing with two noddy classes; Person and Pet
(the full code can be found here:
<http://www.junge.f9.co.uk/code/CustomClassDDL.zip>).
The notion is a Person has a Pet, so the Pet is a property of the
Person object. However when I try and use this relationship against a
DropDownList I can't figure out how to get it to work, as in:
Pet moDino = new Pet(1, "Dino", 4);
Person moFranz = new Person(99, "Mr", "Flintstone", moDino);
ArrayList marrPeople = new ArrayList();
marrPeople.Add(moFranz);
ddlPeople.DataValueField = "Id";
ddlPeople.DataTextField = "MyPet.Name";
ddlPeople.DataSource = marrPeople;
ddlPeople.DataBind();
I've also tried variations like:
ddlPeople.DataTextField = "((Pet) MyPet).Name";
but still didn't get anywhere
I just get the error "DataBinder.Eval: 'Person' does not contain a
property with the name MyPet.Name."
However I know I can do this in a datagrid by casting in the
DataBinder.Eval in the HTML view, but can't figure the equivalent for
the code behind
Any help much appreciated