Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Binding Multiple Types To DataGrid

Thread Tools

Binding Multiple Types To DataGrid

Posts: n/a

In my webapp, I have several types of object that derive from an
abstract base class.

abstract class CMSItem
class Page : CMSItem
class Folder : CMSItem
class Site : CMSItem

This base class contains some abstract fields, Id, Title, IconFileName
which are all overriden in the subclasses.

I have an array of CMSItem objects, which I want to bind to a
DataGrid. The only properties I'm trying to access on the datagrid
are ones which are in the base CMSItem type. But when I try and bind
I get:

System.Reflection.TargetException: Object does not match target type.

Why is this? Does the DataGrid only bind when all objects are of the
same class?

This is really annoying. As a workaround I'm thinking that I may have
to create a specific class for displaying these items in the DataGrid,
and have some static method which can convert items of CMSItem to some
non abstract type, but I'm surprised that what I'm doing isn't

Any ideas?

Many thanks.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView binding - how to stop initial binding Amit ASP .Net 6 10-24-2006 08:06 AM
pywin32 COM sort in Excel (late binding fails, early binding works) (+py2exe) Python 2 10-20-2006 04:08 PM
Datagrid with multiple row types Greif ASP .Net Datagrid Control 1 06-02-2005 09:51 AM
DataGrid Binding Question - Multiple Rows as One. Mike ASP .Net Datagrid Control 1 10-14-2004 04:49 PM
Data Binding - using inline code vs. functions vs. straight binding Jordan ASP .Net 2 02-10-2004 08:32 PM