title: GridView loses column contents during PostBack
body: <p>I am having an issue with the behavior of a <strong>GridView</strong> between post backs.</p>
  
  <p>The real problem comes from a <strong>TemplateField</strong> I define in the markup at <strong>column[0]</strong> with a child <strong>CheckBox</strong> control. Things work fine for the first, and second search executions. However, at some point between the second execution and anything that causes a post back there after, I lose the contents of the TemplateField. </p>
  
  <p>Its only the the contents of the column and not the whole column itself that gets removed. The TemplateField is present in the source and shows a formated column at position 0 of the table.</p>
  
  <p><strong>CODE:</strong></p>
  
  <pre><code>protected void ExecuteSearch(object sender, EventArgs e)
  {
      if (lb_SelectedFields.Items.Count == 0) { return; } //if no selected fields
  
      //Generates custom SQL query based on user inputs and column Selections
      BuildQuery(); // sets txbSqlText.Text = to the SQL string
  
      DataTable Table = SqlAdapter.Select(new System.Data.SqlClient.SqlCommand(txbSqlText.Text));
  
      for (int i = gv_SearchResults.Columns.Count - 1; i &gt; 0; i--) 
      { gv_SearchResults.Columns.RemoveAt(i); } //removes all the columns except[0]
  
      foreach (ListItem Item in lb_SelectedFields.Items) //adds all the user defined columns
      {
          //Column object that is able to find the column definition
          Column Col = ColumnsBasedOnFocus.FindColumName(Item.Value); 
  
          if (Col.Type == "HyperLink") { gv_SearchResults.Columns.Add(CreateHyperLinkField(Col)); }
          else { gv_SearchResults.Columns.Add(CreateBoundColumn(Col, true)); } //true is if the column is visable
      }
  
      gv_SearchResults.DataSource = Table;
      gv_SearchResults.DataBind();
  }
  </code></pre>
  
  <p><strong>ASP.NET:</strong></p>
  
  <pre><code>&lt;asp:GridView ID="gv_SearchResults" runat="server" GridLines="None" CellSpacing="0"
      CellPadding="0" AutoGenerateColumns="false" CssClass="TABLE_LIGHTBLUE" Width="100%"&gt;
      &lt;HeaderStyle CssClass="TABLE_LIGHTBLUE_HEADERROW" /&gt;
      &lt;Columns&gt;
          &lt;asp:TemplateField ItemStyle-Width="30" ItemStyle-Wrap="false"&gt;
              &lt;HeaderTemplate&gt;
                  &lt;center&gt;
                      &lt;asp:Button ID="btn_SelectAll" runat="server" OnClick="SelectAll" Text="All" CssClass="TEXT_SMALL" /&gt;
                      &lt;asp:CheckBox ID="chk_Placeholder" runat="server" Visible="false" /&gt;&lt;/center&gt;
              &lt;/HeaderTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;center&gt;
                      &lt;asp:CheckBox ID="chk_Select" runat="server" Visible="true" /&gt;
                      &lt;asp:Label ID="lbl_AssetGID" runat="server" Visible="false" Text='&lt;%# Bind("i_GID") %&gt;' /&gt;&lt;/center&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>