The Portland White's

Family blogs, photos, files and news.
Welcome to The Portland White's Sign in | Join | Help
in Search

Kelly White

The professional, the personal, and everything else...

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

Anyone ever had this error?  Tried to use an ObjectDataSource with a GridView in ASP.NET 2.0?  Ever followed a tutorial and tweeked it slightly only to have it blow up in your face?

I'm not going to talk about how to wire up the GridView with the ObjectDataSource, there are already great tutorials explaining how to do that.  I'm not even going to talk about how to create your business objects.  What I want to focus on are the entity objects because that is where my problem was at.  I spent forever on Google and couldn't find anyone talking about this.  It turns out (now that I understand it correctly) that I was searching on the wrong thing.  ARGH!!!  Anyways...here is the gist of it, your entity objects cannot just have public members, they must have public properties (get/set).

Huh, that's weird.  And why is that the case, you may ask?  Because you can't databind to a variable.  And why is that?  I don't know, it just is.  Go ask Scott Hanselman if you really want to know.

Be careful reading reading that last link, read the details and don't get caught up in the emotion of the KISS principal like the author tends to emphasize.  That's what caused me this headache in the first place.  Stick out tongue

Originally, my entity object looked like this..

And this was the error I got...

After I changed it to this everything worked.

Published Wednesday, March 07, 2007 1:30 PM by kelly

Comments

No Comments
New Comments to this post are disabled
PDXUX.Net Logo
PDXNA Logo
Powered by Community Server, by Telligent Systems