Asp.net can i databind to fields instead of properties?
I'm getting a List back from a WCF service and I want to set it to be the datasource for a grid. Wh开发者_如何学Cen 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,
~ckBest 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.
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.
精彩评论