PC Review


Reply
Thread Tools Rate Thread

DataField, Binding to a property one level down

 
 
VJ
Guest
Posts: n/a
 
      10th Feb 2007
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
Guest
Posts: n/a
 
      10th Feb 2007
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?
--
Milosz


"VJ" wrote:

> 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
>
>

 
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
Binding control property to class property? Johnny Jörgensen Microsoft C# .NET 5 3rd May 2007 09:22 AM
Binding to property of property of object collection TS Microsoft ASP .NET 3 31st Aug 2006 01:57 PM
Re: Binding to a property Sijin Joseph Microsoft Dot NET Framework Forms 0 16th Sep 2004 12:56 PM
Property Binding Jeremy Cowles Microsoft ADO .NET 3 11th Jul 2003 05:59 PM
Binding the Image property of the picturebox to a another class.property Cade Carvell Microsoft VB .NET 1 9th Jul 2003 05:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:11 PM.