title: C# .net GridView.DataSource
body: <p>In .aspx I have</p>
  
  <pre><code>&lt;body&gt;
    &lt;form id="form2" runat="server"&gt;
   &lt;asp:GridView ID="GridView" runat="server" AutoGenerateColumns="True" Width="100%" ViewStateMode="Enabled"&gt;
   &lt;Columns&gt;
      &lt;asp:BoundField ItemStyle-Width="150px" DataField="id" HeaderText="iD" /&gt;
      &lt;asp:BoundField ItemStyle-Width="150px" DataField="nme" HeaderText="Name" /&gt;
      &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
     &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>In .cs I have</p>
  
  <pre><code>private void Grid()
  {
      string constr = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
      using (SqlConnection con = new SqlConnection(constr))
      {
          using (SqlCommand cmd = new SqlCommand("SELECT id, nme FROM mytable"))
          {
              using (SqlDataAdapter sda = new SqlDataAdapter())
              {
                  cmd.Connection = con;
                  sda.SelectCommand = cmd;
                  using (dt = new DataTable())
                  {
                      sda.Fill(dt);
                      GridView.DataSource = dt; //error occurs here
                      GridView.DataBind();
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>I receive the error 
  CS0120  An object reference is required for the non-static field, method, or property 'BaseDataBoundControl.DataSource'</p>
  
  <p>The .cs does not seem to recognize the GridView from the .aspx page.
  using .net 4.6.1</p>