Traversing properties with a datagrid

N

nmosafi

I have a datagrid that I am binding to a custom collection, and I am
having problems with data binding in an ASP.NET datagrid (1.1
framework).

As a simple example, imagine a class called EmployeeCollection which
inherits CollectionBase, and a class called Employee which is the item
of the collection. Each employee has a manager - also an instance of
the Employee class.

The Employee class has 2 properties

public string Name { get { return this.name; } }

public Employee Manager { get { return this.manager; } }


Now I have created a datagrid with single column, "Employee Name", and
I can successfully bind my collection to it, setting the DataField to
"Name". The problem occurs when I want to add another column "Manager
Name" to the datagrid. If I set the DataField to "Manager.Name" then
it complains that the Manager.Name was not found.

The only workaround for this is to add another property ManagerName to
the Employee class and bind to that as follows:

public string ManagerName { get { return this.Manager.Name; } }


Obviously this is a simplified example - I have many datagrids,
collections, and custom classes, and have ended up adding lots of
methods to retrieve such "sub-properties". This is not ideal.

Is there any way to directly bind the datagrid to Manager's name?
Thanks
Neil
 
N

nmosafi

This is talking about when a property is another collection - you can
bind another datagrid to that property and put it within the parent
datagrid.

However it's not clear about what to do when a property is just an
object, and you want to reference another property of that object and
so on...
 
J

John Saunders

This is talking about when a property is another collection - you can
bind another datagrid to that property and put it within the parent
datagrid.

However it's not clear about what to do when a property is just an
object, and you want to reference another property of that object and
so on...

Manager.Name is not the name of a field, so it gives you that error.

One workaround would be for you to listen to the Item_DataBound event. In
that event, you can set the value of the column to Manager.Name.

John Saunders
 
Z

zest_fien

i keep seeing reviews and raves about this naturalisproducts.com and
organiconline.com.sg . many people are discussing in beauty forums and
magazines have positive reviews on this . but this thing ain't new, its
been around for 20 years! anyone tried can feedback to me on exactly
how good it is?



----------------------------------------
<quote>
(e-mail address removed)
can anyone help me please, am looking for the local distributor or any
shop selling the naturalis range of skin and body care products, from
this company http://www.naturalisproducts.com . looking for this
urgently. for those who have not come across it, its some foodbased
anti-aging products. i googled for this and received result
showing its available at http://www.organiconline.com.sg. i need this
urgently but shipping from singapore will take some time, if anyone is
distributing this please contact me at (e-mail address removed)
urgently. i have a group of us looking to buy this. thanks!
 

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,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top