DataField, Binding to a property one level down

V

VJ

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
 
G

Guest

Hi VJ,

I don't actually think both methods (aspx code and c#) will work for
boundfield (i tested it). However, it will work for templatefield and
Eval("Name.FirstName"). BTW, have you worked for Image Int?
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top