Today I was creating a simple ASP.NET form containing a DataGrid. The type of object to which it's binding has a property named NotifyID. For 15 minutes I tried to understand why I received the following run-time error:
DataBinder.Eval: 'NaturalSelection.Velocity.Inventory.IN_GrowerProductWarehouseNotify' does not contain a property with the name NotifyID .
I had recently renamed the property from InitID to NotifyID. So I scurried about, making sure I hadn't missed anything. I even deleted the cached assemblies from my VSWebCache folder and Temporary ASP.NET Files folder.
Finally, I had the sense to look at my markup. Here's what I saw...
<asp:datagrid ... DataKeyField="NotifyID "... >
Notice the trailing space in the value of attribute DataKeyField. If you look very closely at the aforementioned error message, there's also a trailing space. Apparently, ASP.NET does not trim some, if not all attribute values. It was looking for a property named "NotifyID ".
It's been my practice to always create DataGrids by hand in the HTML view. By now, I've created several hundred. This is the first time I've done that.
--
Sean Winstead
Tags: ASP.NET, DataGrid