DataField, Binding to a property one level down



Hi,

I'm certain I'm not the first person to run into this, but here's the
scenario:

I have a collection of objects say of class 'User' which I want to put
as the datasource of a GridView. I can bind to properties of User
fine. But suppose I want to bind to a property one level down. (Say
User has a property of class Name which has 2 properties 'FirstName'
and 'LastName', both strings. So I'd like to be able to put:

<... DataField="Name.FirstName"..> (in xml)
DataField="Name.FirstName'; (in C#)

As far as I know the first is possible (it's smart enough to traverse
down and find FirstName) while the second is not.

My question is why exactly is this and what's a simple or elegant
workaround (using just code behind). I don't want to create a new
class just so that it's more convinient to bind to the grid view, nor
do I want to copy things manually into a datatable, or anything like
that.
Any input appriciated,
VJ

.



Relevant Pages

  • Re: Simple Question - I Think:/
    ... an either/or scenario. ... If you bind it to a grid, ... Bit field and I expected the Display to be true or false but the Actual ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Validators and multiple submit actions
    ... I see the property but how to I bind it to a button ... The scenario is a Master / Content where there is a Sign-in ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: FreeBSD Security Advisory: FreeBSD-SA-01:18.bind
    ... >> Why not make it default in the base system? ... > The best workaround is not using BIND at all. ... Why work around BIND limitiations and do all this sandboxing to try to ... with "unsubscribe freebsd-security" in the body of the message ...
    (FreeBSD-Security)
  • Re: FreeBSD Security Advisory: FreeBSD-SA-01:18.bind
    ... > Why not make it default in the base system? ... The best workaround is not using BIND at all. ... with "unsubscribe freebsd-security" in the body of the message ...
    (FreeBSD-Security)
  • comboBox SelectedValue behaviour
    ... I have an object populated from the database, The object has three properties, ... Regardless when I bind the objectcollection to the DataSourse property I get ... When I get the SelectedValue of the comboBox it returns the selectedIndex ... Has anyone else seen this behaviour and know of a workaround ...
    (microsoft.public.dotnet.languages.csharp)