Binding custom objects to datagrid WITHOUT using Collectionbase

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Binding custom objects to datagrid WITHOUT using Collectionbase

    Hi

    I'm having difficulty bind a collection of custom objects to a
    datagrid. For reasons that I'll explain shortly I can't use
    Collectionbase, so have instead implemented a custom collection with
    the interfaces IList, ICollection and IEnumerable.

    This class works find for indexing or iterating (foreach etc), but
    when set as the datasource for a web datagrid control it throws an
    exception on callinging the datagrids DataBind() method:

    [ArgumentNullException: Value cannot be null.
    Parameter name: component]
    System.ComponentModel.TypeDescriptor.GetProperties (Object
    component, Boolean noCustomTypeDesc) +173
    System.ComponentModel.TypeDescriptor.GetProperties (Object
    component) +7
    System.Web.UI.WebControls.BoundColumn.OnDataBindCo lumn(Object
    sender, EventArgs e) +95
    System.Web.UI.Control.OnDataBinding(EventArgs e) +66
    System.Web.UI.Control.DataBind() +26
    System.Web.UI.Control.DataBind() +86
    System.Web.UI.WebControls.DataGrid.CreateItem(Int3 2 itemIndex,
    Int32 dataSourceIndex, ListItemType itemType, Boolean dataBind, Object
    dataItem, DataGridColumn[] columns, TableRowCollection rows,
    PagedDataSource pagedDataSource) +169
    System.Web.UI.WebControls.DataGrid.CreateControlHi erarchy(Boolean
    useDataSource) +1408
    System.Web.UI.WebControls.BaseDataList.OnDataBindi ng(EventArgs e)
    +49
    System.Web.UI.WebControls.BaseDataList.DataBind() +23
    ASP.test7_aspx.__Render__control1(HtmlTextWriter __output, Control
    parameterContainer) in C:\Inetpub\wwwroot\test\test7.aspx:85
    System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +27
    System.Web.UI.Control.Render(HtmlTextWriter writer) +7
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    System.Web.UI.Page.ProcessRequestMain() +1929



    I'm assuming (but can't be sure) that this error message is because
    the datagrid doesn't know how to bind the custom collection or objects
    to its required datastructure. If this is the case I'd appreciate some
    advice on how to do this.

    If not, then any other help/explanation would be much appreciated.

    To elaborate further, the data in question is being retrieved from an
    Object Database. Object databases can store the objects in their own
    "collections" called sets which provide their own iterators, search,
    indexing etcetera. Hence I do not wish to use Collectionbase since
    this would require copying the OODB sets into the innerList (the sets
    are rather large). Really all I want is a wrapper (and adapter
    pattern) that presents these sets as a collection that can be bound to
    the datagrid, eg, implementing a custome collection using ICollection,
    IList and IEnumerable, but calling the OODB methods for iteration,
    indexing etc.

    And it must be capably of binding to a datagrid control.

    One more thing. At present the implementation is in Managed C++,
    (because the OODB API is C++), but solutions in C# are acceptable if
    there is no Managed C++ approach that will work.

    thanks in advance

    Rachel
    Rachel Koktava Guest

  2. Similar Questions and Discussions

    1. Complex data binding question, binding child objects of a custom collection.
      I have a custom collection of objects, each of which includes a child object called MyUserOpener. In declarative binding, I can bind this property...
    2. How to recreate custom rows w/o re-binding?
      Here is the problem: I create a grid, which in ItemCreated() adds in custom header rows on changes in a particular field's value. All...
    3. binding DataGrids to a Custom Collection
      Hi, Has anyone read Jan Tielens article on Data binding and Web Services using Custom Collections? ...
    4. Custom Component and Custom Textbox binding
      Hi, I am trying to accomplish the following. Here is what I want to do: 1. Drop a custom business object component onto the design surface...
    5. Binding to a Custom Component from a Custom Control
      I have been experimenting with attaching a component to a custom control as a property. The property grid correctly lists the available...
  3. #2

    Default Re: Binding custom objects to datagrid WITHOUT using Collectionbase

    Hi,

    As I understand it, the Web DataGrid only supports simple databinding
    (through IEnumerable) so when you bind to a custom object it just uses
    IEnumerable to get the next object in the collection then uses reflection to
    get the value of the property that you have bound. The DataGrid should be
    able to deal with null values for the properties.

    Does your collection is implement ITypedList or the individual business
    objects implement ICustomTypeDescriptor?

    There is a KB article (number 316672) that talks about how to handle null
    values in a DataGrid Web Control but it is not very helpful.

    --
    Ross Donald
    Rad Software
    [url]http://www.radsoftware.com.au/web/WebLog/[/url]

    "Rachel Koktava" <rkoktava@talk21.com> wrote in message
    news:875929f1.0309010204.4976a003@posting.google.c om...
    > Hi
    >
    > I'm having difficulty bind a collection of custom objects to a
    > datagrid. For reasons that I'll explain shortly I can't use
    > Collectionbase, so have instead implemented a custom collection with
    > the interfaces IList, ICollection and IEnumerable.
    >
    > This class works find for indexing or iterating (foreach etc), but
    > when set as the datasource for a web datagrid control it throws an
    > exception on callinging the datagrids DataBind() method:
    >
    > [ArgumentNullException: Value cannot be null.
    > Parameter name: component]
    > System.ComponentModel.TypeDescriptor.GetProperties (Object
    > component, Boolean noCustomTypeDesc) +173
    > System.ComponentModel.TypeDescriptor.GetProperties (Object
    > component) +7
    > System.Web.UI.WebControls.BoundColumn.OnDataBindCo lumn(Object
    > sender, EventArgs e) +95
    > System.Web.UI.Control.OnDataBinding(EventArgs e) +66
    > System.Web.UI.Control.DataBind() +26
    > System.Web.UI.Control.DataBind() +86
    > System.Web.UI.WebControls.DataGrid.CreateItem(Int3 2 itemIndex,
    > Int32 dataSourceIndex, ListItemType itemType, Boolean dataBind, Object
    > dataItem, DataGridColumn[] columns, TableRowCollection rows,
    > PagedDataSource pagedDataSource) +169
    > System.Web.UI.WebControls.DataGrid.CreateControlHi erarchy(Boolean
    > useDataSource) +1408
    > System.Web.UI.WebControls.BaseDataList.OnDataBindi ng(EventArgs e)
    > +49
    > System.Web.UI.WebControls.BaseDataList.DataBind() +23
    > ASP.test7_aspx.__Render__control1(HtmlTextWriter __output, Control
    > parameterContainer) in C:\Inetpub\wwwroot\test\test7.aspx:85
    > System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +27
    > System.Web.UI.Control.Render(HtmlTextWriter writer) +7
    > System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    > System.Web.UI.Page.ProcessRequestMain() +1929
    >
    >
    >
    > I'm assuming (but can't be sure) that this error message is because
    > the datagrid doesn't know how to bind the custom collection or objects
    > to its required datastructure. If this is the case I'd appreciate some
    > advice on how to do this.
    >
    > If not, then any other help/explanation would be much appreciated.
    >
    > To elaborate further, the data in question is being retrieved from an
    > Object Database. Object databases can store the objects in their own
    > "collections" called sets which provide their own iterators, search,
    > indexing etcetera. Hence I do not wish to use Collectionbase since
    > this would require copying the OODB sets into the innerList (the sets
    > are rather large). Really all I want is a wrapper (and adapter
    > pattern) that presents these sets as a collection that can be bound to
    > the datagrid, eg, implementing a custome collection using ICollection,
    > IList and IEnumerable, but calling the OODB methods for iteration,
    > indexing etc.
    >
    > And it must be capably of binding to a datagrid control.
    >
    > One more thing. At present the implementation is in Managed C++,
    > (because the OODB API is C++), but solutions in C# are acceptable if
    > there is no Managed C++ approach that will work.
    >
    > thanks in advance
    >
    > Rachel

    Ross Donald Guest

  4. #3

    Default Re: Binding custom objects to datagrid WITHOUT using Collectionbase

    Hi

    In follow up to my previous posting it would seem that you don't need
    to implement ITypedList. In fact a Managed C++ class that implements
    IList, ICollection and IEnumerable doesn't need to do anything to bind
    to a datagrid. The exception was caused by the mechanism that a
    datagrid uses to bind to the collection.

    Under the covers it would seem that the datagrid doesn't extract data
    by using the Enumerator and walking the collection, but by using the
    indexer e.g something line

    for(int i=0; i < myCollection.Count; i++
    {
    datagrid[j]=myCollection[i];
    }

    because I was using the collection to represent an OO extent, I'd
    defined the indexer (using
    [System::Reflection::DefaultMemberAttribute]) to map to the extend
    index for fast look ups. Hence the datagrid couldn't bind because it
    would start doing the for loop and fail on i=0;

    I've posted this in case it may help someone in the future.

    regards
    Rachel
    Rachel Koktava Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139