Nested GridView Class

I am developing an ASP.NET page on localhost and then uploading it to the server. On localhost, I am successfully using nested classes in the DataField property of the BoundField for the GridView. By nested class I mean this: DataField="Object.property"

where Object

is the property of the data item associated with the GridView row. Everything works fine. But when I publish the website to the server, an exception is thrown:

A field or property named "Object.property" was not found in the selected data source.

I tried to find a solution and found this: GridView is bound to nested class properties

I kept finding, but it was mentioned everywhere that using nested classes in related scopes is not possible. But it works like a charm for me on localhost.

Does anyone know why? Is it the latest version of the .NET Framework (I installed 4.5 on localhost and version 4 on the server) or what? Yes, obviously the version is the reason, but I didn't find any mention of it.

Thanks for the clarification. Uiii

+3


source to share


1 answer


The BoundField column only shows the immediate bound properties to the instance

This way we can use DataBinder.Eval in ItemTemplate to access the nested property of the class.

Here's the Code:



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

      

0


source







All Articles