Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Traversing properties with a datagrid

 
Thread Tools Search this Thread
Old 01-04-2005, 11:40 AM   #1
Default 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



nmosafi@gmail.com
  Reply With Quote
Old 01-04-2005, 02:22 PM   #2
Saravana
 
Posts: n/a
Default Re: Traversing properties with a datagrid
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
  Reply With Quote
Old 01-04-2005, 02:38 PM   #3
nmosafi@gmail.com
 
Posts: n/a
Default Re: Traversing properties with a datagrid
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
  Reply With Quote
Old 01-04-2005, 03:51 PM   #4
John Saunders
 
Posts: n/a
Default Re: Traversing properties with a datagrid
<> 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
  Reply With Quote
Old 01-04-2005, 04:08 PM   #5
zest_fien@yahoo.com
 
Posts: n/a
Default Re: Traversing properties with a datagrid
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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46