views:

33

answers:

2

Hi All, I'm getting a List back from a WCF service and I want to set it to be the datasource for a grid. When I databind I get the error that "Deviceheader" is not a property of someObject.

 <td><%# Eval("Deviceheader.DeviceID") %></td>

That is true, it's not a property, it's a public field

public class someObject(){

  public DeviceHeaderDc Deviceheader;

}

How can I databind to these fields since they are not implemented as properties? Any suggestions? I'd like to avoid writing wrapper objects with property implementations if at all possible. If anyone has any tips or tricks I can use here, I'm all ears.

Cheers,
~ck

+1  A: 

Why not just define them as auto properties like so

public DeviceHeaderDc Deviceheader { get; set;}

This way the backing field will be auto generated which gives you the flexibility of changing the back later if you want.

Christopherous 5000
Yes, i agree, there is no reason why you shouldn't implement the field as properties, especially since the introduction of automatic properties.
Wallace Breza
+1  A: 

Best to write a RowDataBound event for the grid. Use a literal control or server bind your TD tag. Then you can use whatever you want to bind to the field. I can provide an example if you want.

Carter
There were hundreds of objects in this case so converting to AutoProperties wasn't feasable. This worked just fine for my situation. Thanks!
Hcabnettek