Cannot bind IList returned from a web service to a repeater

B

Baohua Li

After I retrieved a list of objects (e.g Employees) and put it into a IList
(ArrayList)
and bind it to a repeater. everything works fine so far.

However, when I get a IList from a web service, it failed. The error is
"Cannot find the property".
But, I can get/set the properties in my programs without problem.

TIA

Li
 
J

Jan Tielens

The problem is that the members of your real Employee class are implemented
as public properties, but on the generated proxy class, they are implemented
as public fields. You can check this in the Reference.vb or cs file that was
generated when you added a web reference to your client project.

Databound user controls bind to properties, not to fields. For example when
you try to display the collection in an DataGrid, you won't see any columns
either because the DataGrid looks for properties.

A solution is to alter the generated proxy class and change the fields to
properties. But be aware you'd have to do this each time you update your
webservice. A more generic way of solving this issue is to create a wrapper
class that dynamically at run-time wraps your proxy class into a new class
that exposes the fields as properties. I wrote an article about this matter,
you can find it here:
http://www.microsoft.com/belux/nl/msdn/community/columns/jtielens/webservice
wrapper.mspx
Full source code is available and can be downloaded.
--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
 
B

Baohua Li

Thank you very much!

Jan Tielens said:
The problem is that the members of your real Employee class are implemented
as public properties, but on the generated proxy class, they are implemented
as public fields. You can check this in the Reference.vb or cs file that was
generated when you added a web reference to your client project.

Databound user controls bind to properties, not to fields. For example when
you try to display the collection in an DataGrid, you won't see any columns
either because the DataGrid looks for properties.

A solution is to alter the generated proxy class and change the fields to
properties. But be aware you'd have to do this each time you update your
webservice. A more generic way of solving this issue is to create a wrapper
class that dynamically at run-time wraps your proxy class into a new class
that exposes the fields as properties. I wrote an article about this matter,
you can find it here:
http://www.microsoft.com/belux/nl/msdn/community/columns/jtielens/webservice
wrapper.mspx
Full source code is available and can be downloaded.
--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
 

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

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top