![]() |
|
|
|||||||
![]() |
ASP Net - Traversing properties with a datagrid |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 nmosafi@gmail.com |
|
|
|
|
#2 |
|
Posts: n/a
|
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 <> wrote in message news: 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 > Saravana |
|
|
|
#3 |
|
Posts: n/a
|
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... nmosafi@gmail.com |
|
|
|
#4 |
|
Posts: n/a
|
<> wrote in message
news: 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 John Saunders |
|
|
|
#5 |
|
Posts: n/a
|
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! zest_fien@yahoo.com |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Get datagrid textbox value | kanchangorak | Software | 0 | 03-11-2009 11:11 AM |
| Loading 24,000 rows into C# .net Datagrid | Kagu | Software | 0 | 03-10-2009 06:51 PM |
| validating textbox inside datagrid | susan_1516 | Software | 0 | 11-09-2008 01:29 PM |
| ASP.NET VB Using ItemDataBound to create textbox in datagrid rows. | smi59550 | General Help Related Topics | 0 | 01-18-2008 07:42 PM |
| Disable ASP Button in a Datagrid | ChrisClayko | General Help Related Topics | 0 | 08-02-2006 03:08 AM |