Traversing properties with a datagrid

Discussion in 'ASP .Net' started by nmosafi@gmail.com, Jan 4, 2005.

  1. Guest

    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
     
    , Jan 4, 2005
    #1
    1. Advertising

  2. Saravana Guest

    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:...
    > 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, Jan 4, 2005
    #2
    1. Advertising

  3. Guest

    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...
     
    , Jan 4, 2005
    #3
  4. <> wrote in message
    news:...
    > 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, Jan 4, 2005
    #4
  5. Guest

    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>

    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
    urgently. i have a group of us looking to buy this. thanks!
     
    , Jan 4, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. steven
    Replies:
    6
    Views:
    916
    steven
    Aug 27, 2003
  2. Asad

    XML - traversing in VB

    Asad, Apr 16, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    585
    Matt Berther
    Apr 16, 2004
  3. =?Utf-8?B?c2xpbV9uYWxkeQ==?=

    traversing a client directory in ASP.NET

    =?Utf-8?B?c2xpbV9uYWxkeQ==?=, May 10, 2005, in forum: ASP .Net
    Replies:
    10
    Views:
    818
    Scott M.
    May 12, 2005
  4. EdG
    Replies:
    9
    Views:
    247
    Steven D'Aprano
    Jan 19, 2007
  5. X
    Replies:
    1
    Views:
    85
    Mike Foster
    Jun 16, 2004
Loading...

Share This Page