Groups | Blog | Home
all groups > asp.net datagrid control > october 2004 >

asp.net datagrid control : databinding & classes


Bart
10/26/2004 6:23:02 AM
I made an arraylist wich contains a certain amount of objects from the class
'employees'. The class 'employees' contains also an object 'department'. You
can see the class diagram (http://users.pandora.be/bart.geurs/class.gif).

The next step is to bind that arraylist to a datagrid. It works, but I only
see the data from the 'root'-object employee. I cannot get the data from the
department-object into that datagrid.

Code :
dim list as new arraylist
list=fillList() --> sub wich handles the filling of the arraylist

datagrid1.datasource=list
datagrid1.databind()

How can I get the data from the 'sub-object' into the datagrid ? Or maybe
Flare
10/30/2004 12:05:13 PM

[quoted text, click to view]

ArrayList is fine. But think about what you are trying to do. How would you
want your nested object to show? The "right" way is to show a treelike
structure where all root objects (employee) was shown and a + sign was shown
so you could "out-fold" the nested object (Department).

Anyway. Datagrid does not support neted objects so you want to do something
like this in the <itemtemplate> or/and <edititemtamplete>

EG:
<asp:label id="Label1" runat="server" Text="<%# (Container.DataItem as
Employee.Department).name %>"></asp:label>

Reagards
Anders Jacobsen, Denmark

AddThis Social Bookmark Button