Binding Multiple Types To DataGrid

Discussion in 'ASP .Net Datagrid Control' started by Gargamel, May 24, 2004.

  1. Gargamel

    Gargamel Guest

    Hi.

    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
    working.

    Any ideas?

    Many thanks.

    R.
     
    Gargamel, May 24, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jordan
    Replies:
    2
    Views:
    2,539
    Jordan
    Feb 10, 2004
  2. Amit
    Replies:
    6
    Views:
    13,819
    Assimalyst
    Oct 24, 2006
  3. Replies:
    2
    Views:
    868
    Kevin Grover
    Oct 20, 2006
  4. Mike

    DataGrid Binding Question - Multiple Rows as One.

    Mike, Oct 13, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    135
  5. Greif

    Datagrid with multiple row types

    Greif, Jun 1, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    163
    Eliyahu Goldin
    Jun 2, 2005
Loading...

Share This Page