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 asp.net application in my local machine, I encountered an exception which is the title of this post. This asp.net 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" />  
 </asp:BoundField>  
(Windows 7 32 Bit using TemplateField)
  <asp:TemplateField HeaderText="Product Name">  
     <ItemStyle Width="350px"/>  
     <ItemTemplate>  
     <asp:Label ID="lblProductName" Text='<%# Eval("Product.Name")%>' runat="server">     
     </asp:Label>  
     </ItemTemplate>                
  </asp:TemplateField>  
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.
Cheers!

0 comments:

Post a Comment