title: ASP.NET GridView Custom Binding Error
body: <p>I was given the task of designing a ORM + Object Model for our product. It has primarily been used for Windows + WinForms development but it is now needing to be used with our ASP.NET products as well. </p>
  
  <p>However there seems to be a problem with binding the Collection object to a GridView (and I suspect other ASP.NET data source controls). </p>
  
  <p>The online dev team get the following error </p>
  
  <p><code>[HttpException (0x80004005): The IListSource does not contain a data source named ''.  Check your DataMember value.]</code></p>
  
  <p>The collection object we use uses a 'view' collection to handle sorting / filtering (similar to how a DataView relates to a DataTable) and this is the 'List' that the IListSource implementation returns. But for some reason the ASP.NET control isn't happy with it and throws an exception. </p>
  
  <p>If I use the Linq extension method 'ToList' on the collection, it binds successfully - but converting a list to a list seems pretty pointless and as the GridView binds to DataTables which also implement IListSource it must be something I've done wrong in the object model.</p>
  
  <p>But I'm a bit lost as to where to look, it seems most of the google examples show binding to a dataset so not particularly helpful.</p>
  
  <p>As always, any insights welcomed.</p>
  
  <p>edit</p>
  
  <hr>
  
  <p>AlumniShopItems is of type:</p>
  
  <p><code>DataObjectCollection&lt;AlumniShopItem&gt;</code> </p>
  
  <p>which is a subclass of: </p>
  
  <p><code>DataObjectCollection&lt;T&gt; : BindingList&lt;T&gt;, IListSource, IList&lt;T&gt;, IDataObjectCollection, IFillableList where T : DataObject</code></p>
  
  <p>IListSource returns the following typed list: <code>ObjectListView&lt;T&gt;</code></p>
  
  <p>which intern implements the following interfaces:</p>
  
  <p><code>IBindingListView, IList&lt;T&gt;, ITypedList, IRaiseItemChangedEvents, ICancelAddNew, IDeserializationCallback</code></p>
  
  <hr>
  
  <p>Thanks </p>
  
  <p>Marlon</p>
  
  <p>Below is the code they're using:</p>
  
  <pre><code> &lt;asp:GridView ID="ShopGrid" runat="server" AutoGenerateColumns="False" AutoGenerateEditButton="True"
                          OnRowEditing="ShopGrid_RowEditing" 
                OnRowUpdating="ShopGrid_RowUpdating" OnRowCancelingEdit="CancelEdit" 
                OnRowDataBound="RowBinding" &gt;
                          &lt;Columns&gt;
                              &lt;asp:TemplateField HeaderText="ID" Visible="false"&gt;
                                  &lt;EditItemTemplate&gt;
                                       &lt;asp:Label ID="Label1" runat="server" Text='&lt;%#Bind("Ident")%&gt;'&gt;&lt;/asp:Label&gt;
                                  &lt;/EditItemTemplate&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:Label ID="Label1" runat="server" Text='&lt;%#Bind("Ident")%&gt;'&gt;&lt;/asp:Label&gt;
                                  &lt;/ItemTemplate&gt;
                              &lt;/asp:TemplateField&gt;
                                &lt;asp:TemplateField HeaderText="Item Name" &gt;
                                  &lt;EditItemTemplate&gt;
                                       &lt;asp:TextBox ID="NameText" runat="server" Text='&lt;%#Bind("Name")%&gt;'&gt;&lt;/asp:TextBox&gt;
                                  &lt;/EditItemTemplate&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:Label ID="NameLabel" runat="server" Text='&lt;%#Bind("Name")%&gt;'&gt;&lt;/asp:Label&gt;
                                  &lt;/ItemTemplate&gt;
                              &lt;/asp:TemplateField&gt;
                              &lt;asp:TemplateField HeaderText="Pay Pal ID" &gt;
                                  &lt;EditItemTemplate&gt;
                                       &lt;asp:TextBox ID="PayPalText" runat="server" Text='&lt;%#Bind("PayPalID")%&gt;'&gt;&lt;/asp:TextBox&gt;
                                  &lt;/EditItemTemplate&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:Label ID="PayPalLabel" runat="server" Text='&lt;%#Bind("PayPalID")%&gt;'&gt;&lt;/asp:Label&gt;
                                  &lt;/ItemTemplate&gt;
                              &lt;/asp:TemplateField&gt;
                              &lt;asp:TemplateField HeaderText="Price" &gt;
                                  &lt;EditItemTemplate&gt;
                                       &lt;asp:TextBox ID="PhotoPath" runat="server" Text="" &gt; &lt;/asp:TextBox&gt;
                                       &amp;nbsp;&amp;nbsp;&amp;nbsp;
                                       &lt;asp:Button ID="Upload" runat="server" Text="Upload" /&gt;
                                  &lt;/EditItemTemplate&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:Image ID="itemPhoto" runat="server" /&gt;
                                  &lt;/ItemTemplate&gt;
                              &lt;/asp:TemplateField&gt;
                                &lt;asp:TemplateField HeaderText="Price" &gt;
                                  &lt;EditItemTemplate&gt;
                                        &lt;asp:CheckBox ID="CheckBox1" runat="server" Checked='&lt;%#Bind("Current")%&gt;' Enabled="true" /&gt;
                                  &lt;/EditItemTemplate&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:CheckBox ID="CheckBox1" runat="server" Checked='&lt;%#Bind("Current")%&gt;' Enabled="false" /&gt;
                                  &lt;/ItemTemplate&gt;
                              &lt;/asp:TemplateField&gt;
                          &lt;/Columns&gt;
                      &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Somewhere in page load:</p>
  
  <pre><code>Line 57:                 alumniShopItems.FillMe();
  Line 58:                 ShopGrid.DataSource = alumniShopItems;
  Line 59:                 ShopGrid.DataBind();
  </code></pre>