DataBinding to Array of Custom Objects

J

Jed

I have a web service method that returns an array of custom objects marked
serializeable with fully described public properties.

When I bind the results to a DataGrid I can access the properties in the
ItemDataBound event of the codebehind but I can't access them declaratively
in the HTML code?

Here is the code to call the method.
net.mysite.www.WSInterface proxy;
proxy = new net.mysite.www.WSInterface();
ProjectList[] pl = proxy.getProjects("%",false,true);
this.DataGrid1.DataSource = pl;
this.DataGrid1.DataBind();

Here is the code to access the property in the Item databound event.
lbl.Text = ((ProjectList)dg.DataItem).ClientName;

Here is the code that won't work on the HTML side:
Option 1:
<asp:BoundColumn HeaderText="Client Contact"
DataField="ClientContact"></asp:BoundColumn>

Option 2:
<asp:TemplateColumn HeaderText="Contact">
<ItemTemplate><%# DataBinder.Eval(Container.DataItem,
"ClientContact")%></ItemTemplate>
</asp:TemplateColumn>

Here is the error:
DataBinder.Eval: 'net.mysite.www.ProjectList' does not contain a property
with the name ClientContact.

Why can I access the property in the ItemDataBound event but not on the
declarative side?

The Page obviously know what kind of Object the data item is, otherwise the
error could not report it.

Any ideas? Thanks!
 
B

Bob Barrows [MVP]

Jed said:
I have a web service method that returns an array of custom objects
marked serializeable with fully described public properties.

When I bind the results to a DataGrid I can access the properties in

There was no way for you to know it, but this is a classic asp newsgroup.
While you may be lucky enough to find a dotnet-savvy person here who can
answer your question, you can eliminate the luck factor by posting your
question to a group where those dotnet-savvy people hang out. I suggest
microsoft.public.dotnet.framework.adonet or
microsoft.public.dotnet.framework.aspnet.
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top