Tuesday, July 24, 2007

GridView and the ObjectDataSource

TheDotNetGuy "Since, we are working with ObjectDataSource control we need to make an entity class. Take a look at the simple User class below:" It took me quite a while to figure out some of the subtle features that needed to be set in order to implement a custom paging setup for the GridView. These are the three most important things I learned: 1. an entity class is required for the ObjectDataSource to run off of. 2. If the ObjectDataSource's entity class is inside a namespace then the entire name (namespace included) must be given to the ObjectDataSource.TypeName and not just the class name. 3. It isn't enough to have public fields in the entity class as the GridView will only look at public properties (essentially a public field that acts like a method with get and set statements). Here is the other website that really helped out with this: http://unboxedsolutions.com/sean/archive/2005/01/22/428.aspx "Well, it's not that I buy into what JayBaz says about properties. I was just hastily writing some test code without any regard to my flippancy. As soon as a changed the public fields to properties, TADA!" Here were the errors I was gettings: 1. The type specified in the TypeName property of ObjectDataSource 'objItem' could not be found. 2. The data source for GridView with id 'grdContacts' did not have any properties or attributes from which to generate columns. Ensure that your data source has content.

No comments: