Good catch! New records are indeed missing the DataKeyValues since there is no data bound to the Insert item. When executing logic while inserting/editing, it is very important to make a difference between the two, thus you can avoid issues like the one you have experienced.
Another tip that I would like to share, and it happens to be a crucial one when developing apps with AJAX enabled. Disable AJAX during the time of developing the application: Get more descriptive errors by disabling AJAX
What AJAX does, is trying to communicate with the server without making an entire PostBack, thus the page flickering and others are eliminated. AJAX is not the key component in an application, it is more like applying polish on an existing product.
Here comes the ISSUE.
If developing an application, which is not ready for deployment, most probably it will be tested several times for potential errors. If there are runtime errors, it is expected to throw the exception and show it on the surface, but nothing happens. The reason is that AJAX will most likely catch the error comming back from the server and prevent it from showing up on the client. Until the developer realizes, that there is an error and is hidden, he most likely spends lot of his time to revert back the changes he made, or change other lines, etc...
Here comes the SOLUTION:
By not having AJAX enabled on the page during the development process, all errors will come up and face the surface. This will precisely tell the developers where the error is originating, and what is its nature. Having that instantly as you make a change would drastically reduce developing time.
Get quickly onboarded and successful
with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.