Binding array of objects to datagrid

  • Thread starter Thread starter Morten
  • Start date Start date
M

Morten

Hi!

I've made my own webservice which returns a collection of objects with 4
properties (or fields when they get returned from the webservice...).

Is there an easy way to display each object in the collection and its
properties (fields) in a datagrid? Maybe I can build a multidimensional
array and bind that to the grid?

Help is appreciated.

Morten
 
Hi!

I tried that but unfortunately that gives me the error: DataGrid with id
'DataGrid1' could not automatically generate any columns from the selected
data source.

I guess that could be because one of my properties is a string array?

Any other suggestions?

Morten
 
Hi!

It's a web grid. Could you give me an example or give me an address that
shows how to do this?

Morten
 
if you want finer degree of control :

<asp:datagrid id="grid" runat="server" autogeneratecolumns="false">
<columns>
<asp:TemplateColumn>
<ItemTemplate>
<%# ((MyNameSpace.MyClass)Container.DataItem).MyField1 %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<%# ((MyNameSpace.MyClass)Container.DataItem).MyField2 %>
</ItemTemplate>
</asp:TemplateColumn>
</columns>
</asp:datagrid>

or

<asp:datagrid id="grid" runat="server" autogeneratecolumns="false">
<columns>
<asp:BoundColumn DataTextField="MyField1" />
<asp:BoundColumn DataTextField="MyField2" />
</columns>
</asp:datagrid>
 
Back
Top