4

I'm developing ASP.NET page on localhost and then uploading it on the server. On localhost I successfuly use nested classes in DataField property of BoundField of an GridView. By nested class I mean this: DataField="Object.property" where Object is a property of the data item bound to the row of the GridView. Everything works fine. But when I publish the website on the server, an exception occures:

A field or property with the name 'Object.property' was not found on the selected data source.

I was trying to find the solution and found this: GridView bound with Properties of nested class

I continued finding, but everywhere was mentioned that using nested classes in boundfields isn't possible. But its working like a charm for me on localhost.

Does anyone know why? Is it the latest version of .NET Framework (I have installed version 4.5 on localhost and version 4 on the server) or what? Yes it looks obvious that the version is the reason, but I haven't found any mention about it.

Thanks for your clarification. Uiii

Community
  • 1
  • 1
uiii
  • 469
  • 1
  • 7
  • 19

1 Answers1

0

BoundField column show only immediate associated properties to instance

So there is only way that we have to use DataBinder.Eval in an ItemTemplate to access the nested class property.

Here's Code :

<asp:TemplateField>
<ItemTemplate>
    <%#DataBinder.Eval(Container.DataItem, "NestedClass.Name")%>
</ItemTemplate>

Rahul Nikate
  • 6,192
  • 5
  • 42
  • 54