title: ASP.NET Error when binding a GridView to a List of Objects?
body: <h2>Error Message:</h2>
  
  <blockquote>
    <p>The data source for GridView with id 'FormProprietari' did not have
    any properties or attributes from which to generate columns.  Ensure
    that your data source has content.</p>
  </blockquote>
  
  <p>I have a ASP.NEt application in which I try to bind a <code>GridView</code> to a <code>List&lt;T&gt;</code> objects which from what I can tell on the net it should be possible.</p>
  
  <p>This is my <code>GridView</code>:</p>
  
  <pre><code>&lt;asp:GridView ID="FormProprietari" runat="server"&gt;
          &lt;Columns&gt;
              &lt;asp:TemplateField &gt;
                   &lt;ItemTemplate&gt; 
                      &lt;%#((Lab_TAP_web.Proprietar)Container.DataItem).NumeProprietar%&gt; 
                   &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
  
              &lt;asp:TemplateField &gt;
                   &lt;ItemTemplate&gt; 
                      &lt;%#((Lab_TAP_web.Proprietar)Container.DataItem).PrenumeProprietar%&gt; 
                   &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
  
              &lt;asp:TemplateField &gt;
                   &lt;ItemTemplate&gt; 
                      &lt;%#((Lab_TAP_web.Proprietar)Container.DataItem).ProprietarID%&gt; 
                   &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
          &lt;/Columns&gt;
  
      &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>And this is the function in which I add a new object of the <code>Proprietar</code> class I defined to the database then rebind the gridview to show it, I should mention that intially the database is empty and so is the gridview i,e it doesn't show up.</p>
  
  <pre><code>protected void Button2_Click(object sender, EventArgs e)
          {
              var Nume = TBNumeProprietar.Text;
              var Prenume = TBPreNumeProprietar.Text;
  
              MyCars db = DBSilo.db;
  
              Proprietar newOwner = new Proprietar();
              newOwner.NumeProprietar = Nume;
              newOwner.PrenumeProprietar = Prenume;
              newOwner.ProprietarID = (db.Proprietari.Count() + 1);
              //newOwner.ProprietarID = 1;
  
  
  
              db.Proprietari.InsertOnSubmit(newOwner);
              db.SubmitChanges();
  
              try
              {
                  FormProprietari.DataSource = db.Proprietari.ToList();
              }
              catch (Exception)
              {
  
                  throw;
              }
              FormProprietari.DataBind();           
          }
  </code></pre>
  
  <p>The problem being that I checked the <code>List&lt;Proprietar&gt;</code> which is the data source with breakpoints and the list always contains a <code>Proprietar</code> object.</p>
  
  <p>Does anyone have a idea what I did wrong?</p>