473,468 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Traversing properties with a datagrid

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

Nov 19 '05 #1
4 1322
Check out "Binding to Hierarchical Data" section in this article, it might
help you.
http://www.devx.com/dotnet/Article/22024/1954?pf=true

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
<nm*****@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
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

Nov 19 '05 #2
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...

Nov 19 '05 #3
<nm*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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
Nov 19 '05 #4
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>
g...@raterenterprise.com
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 g...@raterenterprise.com
urgently. i have a group of us looking to buy this. thanks!

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Plamen Valtchev | last post by:
This is my problem: From JavaScript I want to find the list of all defined/loaded JavaScript functions/objects/names within the current scope (html page in a browser). the page could contain...
1
by: X | last post by:
I cannot figure this one out. I would like to traverse through and elements styles (not class) and get a list of all properties using javascript property names and css property names along with the...
2
by: Marty McDonald | last post by:
When setting certain datagrid properties with the IDE (as in the property window), they don't seem to take effect. For instance, Font Name. So I have to set these via code-behind at the cell...
4
by: plmanikandan | last post by:
Hi, I am new to link list programming.I need to traverse from the end of link list.Is there any way to find the end of link list without traversing from start(i.e traversing from first to find the...
0
by: fig000 | last post by:
Hi, I'm pretty new to the new dot.net. I've been able to quickly set up a grid view with page, etc. The gridview is connected to a drop down which changes the gridview's contents based on the...
9
by: EdG | last post by:
I'm using Python version 2.4 and I created a class with some properties like: def GetCallAmount(self): return somedata def GetCallCurrency(self): return somemoredata more....defs..etc.
0
by: mvanroshum | last post by:
Hi, I have the following problem: The DataSource of a DataGrid can be set to an IList. The DataGrid nicely lists the objects in the IList, showing all the public properties of the objects as...
30
by: asit | last post by:
We kno that data can be pushed onto the stack or popped 4m it. Can stack be traversed ??
1
by: somcool | last post by:
I am facing an error while traversing a query in MS Access Details - When I click a button, a form which has the query opens up. There are certain fields which are in the form of combo box in the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.