title: Why does binding work in code behind but not declaratively?
body: <p>I'm using an ASP.NET GridView. First, I tried to use declarative fields as below, but not to avail. I had an error stating that the binding object had no property Id or Name (but it actually did have them...)</p>
  
  <pre><code> &lt;asp:GridView runat="server" ID="GlobalAnalyticsGridView" OnRowDataBound="GlobalAnalyticsGridView_RowDataBound" AutoGenerateColumns="false"&gt;                        
         &lt;Columns&gt;
               &lt;asp:BoundField DataField="Id" HeaderText="Id" Visible="false" /&gt;
               &lt;asp:BoundField DataField="WebAppName" HeaderText="Web Application" /&gt;                       
         &lt;/Columns&gt;
   &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Then I tried by code, on the RowDataBound event. And it works just fine...</p>
  
  <pre><code> protected void GlobalAnalyticsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
               AnalyticsSettings settings = e.Row.DataItem as AnalyticsSettings;
               (e.Row.Cells[0]).Text = settings.Id;
               (e.Row.Cells[1]).Text = settings.WebAppName;
          }
      }
  </code></pre>
  
  <p>Any idea why is that?
  Thanks for your lighting on this :)</p>