Thursday 3 January 2008

You receive an error "No keys specified for the current object data type" when using an ObjectContainerDatasource in ASP.NET 3.5

Just in case anyone encounters the same issue and can't work it out - I had this error crop up when doing 2-way databinding with an object container datasource (OCDS).

"No keys specified for the current object data type"

When I made my programmatic call to FormView.UpdateItem(false), I was constantly getting this error.

Turns out I was rebinding the FormView outside a postback handler. The fix was to move the
FormView.DataBind() to inside a Page.IsPostback check.

There can also be an issue with bound controls "losing" the DataKeyNames property. You can fix this issue by specifying the DataKeyNames in code - e.g. addToAssetFormView.DataKeyNames = new string[] {"ObjectId"}; before the control is bound (or rebinding with addToAssetFormView.DataBind();)

This problem can occur with any databound controls like gridviews, not just formviews.

1 comment:

Unknown said...

Thanks David,
your post helped me to resolve my problem.

Best regards,
Sidd