Heterogeneous objects and a GridView

B

Bill Ward

I am fairly new to ASP.NET programming and I have hit a problem and I am
looking for the "correct" solution. I have a class A that has derived
classes B and C. I want to display a group of these classes on a web form
using a GridView. To help me accomplish this I have created a class "AList"
derived from IEnumerable<A>. In my web form I have my GridView hooked up to
an ObjectDataSource. The ObjectDataSource has its SelectCountMethod and
SelectMethod attributes referencing appropriate methods of the AList class,
the TypeName is set to "AList" and the DataObjectTypeName is set to "A".
Everything seems to work perfectly until the AList object contains a mixture
of classes. It appears that the GridView uses reflection to inspect the
first object in the list and then assumes that every other object is the
same. Consequently it throws an exception "Object does not match target
type" when it meets an object in the list that is not the of the same type
as the first.
So, my question is what is the correct solution? There seem to be a myriad
of options for the base class of AList. I chose IEnumerable<A> because I
like the type safety that it provides. BindingList and ITypedList seem to be
an alternative option, but the documentation leaves me unsure of many
things. One really good example would be great if anyone can point me in
that direction.

Thanks

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top