A data item was not found in the container. The container must either implement IDataItemContainer, or have a property named DataItem.

Published 07-04-2007 2:44 PM | jokiz

I'm working on a GridView and I'm databinding a List<BusinessObject> to it.  All is well until I tweaked some code and suddenly, I got this System.Web.HttpException with message

A data item was not found in the container. The container must either implement IDataItemContainer, or have a property named DataItem.

I haven't been programming with ASP.NET for a while and I haven't encountered the said exception.  Turned out that I have a null item in the list due to some filtering of data that I have included (transformation from array types to list type is involved). 

The first sentence tells it all "A data item was not found in the container" but I got confused with the second sentence.

Comments

# Ian Jones said on June 25, 2008 6:13 AM:

I just came across the same error.  Never seen it before and it merrily lead me up the wrong garden path!  Thanks for the sanity check.