A Precarious Balance

Sean Winstead's web site & blog
Welcome to A Precarious Balance Sign in | Join | Help
in Search

A Precarious Balance

Sean Winstead's web site & blog

ASP.NET DataGrid.DataKeyField includes trailing spaces

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

Published Wednesday, November 02, 2005 9:48 AM by Sean Winstead
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 
Submit