Binding array of objects to datagrid

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
 
M

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
 
M

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
 
T

The Crow

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top