Thursday, November 14, 2013

A field or property with the name 'ClassName.Property' was not found on the selected data source (ASP.NET Gridview)

As i was running an application in my local machine, I encountered an exception which is the title of this post. This app runs perfectly from the other workstation. I tried searching solutions in google but found out that most of the recommendations were to redo the model or the business tier.

One option I tried was to replace the BoundField of the gridview with TemplateField with label as the bound control using Eval("expression").
Glad that worked. It could be an IIS issue as stated in other forums.
Here's the gridview markup changes:
(Windows 7 64 Bit using BoundField)
 <asp:BoundField DataField="Product.Name" HeaderText="Name" >  
      <ItemStyle Width="350px" />  
(Windows 7 32 Bit using TemplateField)
  <asp:TemplateField HeaderText="Product Name">  
     <ItemStyle Width="350px"/>  
     <asp:Label ID="lblProductName" Text='<%# Eval("Product.Name")%>' runat="server">     
Note: I also tested the program in a Windows 8 64 Bit machine. TemplateField simply works. I believe that BoundField has some issues with 32 bit machines.


Post a Comment