Binding Grid View to Objects??

Discussion in 'ASP .Net' started by Nemisis, Aug 17, 2006.

  1. Nemisis

    Nemisis Guest

    Hi everyone,

    I have now managed to write my own data layer and business layer
    objects, mapped them out etc etc, and it all works fine.

    The problem i am having is that my business object consist of other
    business objects, example below

    Object1
    id
    name
    object2
    object3collection

    Object2 has properties and object3 is a collection of another object.
    How in the grid view can i show the values of these fields??

    I have tried object2.id, and object3collection.item(0).id, but it
    doesnt work. i know there are objects within the collection because i
    always add one, even if there isnt one (for testing)

    Very grateful for any help. Cheers
     
    Nemisis, Aug 17, 2006
    #1
    1. Advertising

  2. If you want a datagrid that shows a bunch of Object1 types then your
    ItemTemplate would be (these are all slightly different and assuming that
    you're doing C# 2.0)....

    <asp:label runat="server" id="id" Text="<%# (Container.DataItem as
    Object1).Id.ToString() %>"/>
    <asp:label runat="server" id="Name" Text="<%# (Container.DataItem as
    Object1).name %>"/>
    <asp:label runat="server" id="SomePropertry" Text="<%# (Container.DataItem
    as Object1).Object2.PropertyName %>"/>
    <asp:label runat="server" id="SomePropertry" Text="<%# (Container.DataItem
    as Object1).Object3Collection[0].PropertyName %>"/>


    <asp:DataGrid runat="server" id="Object3Grid" DataSource="<%#
    (Container.DataItem as Object1).Object3Collection %>"/>



    "Nemisis" wrote:

    > Hi everyone,
    >
    > I have now managed to write my own data layer and business layer
    > objects, mapped them out etc etc, and it all works fine.
    >
    > The problem i am having is that my business object consist of other
    > business objects, example below
    >
    > Object1
    > id
    > name
    > object2
    > object3collection
    >
    > Object2 has properties and object3 is a collection of another object.
    > How in the grid view can i show the values of these fields??
    >
    > I have tried object2.id, and object3collection.item(0).id, but it
    > doesnt work. i know there are objects within the collection because i
    > always add one, even if there isnt one (for testing)
    >
    > Very grateful for any help. Cheers
    >
    >
     
    =?Utf-8?B?RGF2aWQgSmVzc2Vl?=, Aug 17, 2006
    #2
    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. Luqman
    Replies:
    2
    Views:
    3,825
    Luqman
    Feb 1, 2006
  2. Simon L
    Replies:
    3
    Views:
    407
    Jeff Flinn
    Mar 31, 2006
  3. wahtnamas
    Replies:
    0
    Views:
    904
    wahtnamas
    May 1, 2009
  4. vicky_smiles007

    Asynchronus binding grid view

    vicky_smiles007, Jul 17, 2011, in forum: .NET
    Replies:
    0
    Views:
    941
    vicky_smiles007
    Jul 17, 2011
  5. Parthiv Joshi
    Replies:
    1
    Views:
    709
    Samuel L Matzen
    Jul 6, 2004
Loading...

Share This Page