Binding Grid View to Objects??

  • Thread starter Thread starter Nemisis
  • Start date Start date
N

Nemisis

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
 
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 %>"/>
 
Back
Top