Monday 1 August 2011

TargetInvocationException - Object Does Not Match Target Type

If you have a gridview in asp.net that is bound to a list of objects that are not all the same type (they are all derivatives of the same base class) you may get an error saying the Object does not match the target type.

This is because the gridview looks at the type of the first item in the grid and expects all other items to be the same type.

There is an easy work around for this which can be achieved by converting all of the columns to template fields so the properties are evaluated separately.

No comments:

Post a Comment