title: Problem to programmatically add rows to GridView with pre-defined columns
body: <p>Given a GridView control defined like this:</p>
  
  <pre><code>&lt;asp:GridView
        ID="AttachedFilesGridView"
        runat="server"
        AllowSorting="true"
        AllowPaging="false"
        CellPadding="5"
        AutoGenerateColumns="false"
        CssClass="wsajax_DlgCodeBox"&gt;
        &lt;Columns&gt;
          &lt;asp:TemplateField&gt;
            &lt;ItemTemplate&gt;
              &lt;asp:CheckBox ID="CheckSelect" runat="server" /&gt;
            &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:BoundField Datafield="FilePath" HeaderText="File Path" SortExpression="FilePath" /&gt;
          &lt;asp:BoundField Datafield="AttachmentID" HeaderText="Attachment ID" /&gt;
         &lt;/Columns&gt;
    &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>I am attempting to generate rows for the grid view on the server-side in C# using this code:    </p>
  
  <pre><code>DataTable dt = new DataTable();
  dt.Columns.Add(new DataColumn("CheckSelect", typeof(CheckBox))); // &lt;&lt;&lt;--- ?????
  dt.Columns.Add(new DataColumn("FilePath", typeof(string)));
  dt.Columns.Add(new DataColumn("AttachmentID", typeof(string)));
  
  string errMsg = String.Empty;
  char[] delimiters = { ',' };
  string[] pendingsIDs = PendingFileAttachments.Value.Split(delimiters,     StringSplitOptions.RemoveEmptyEntries);
  foreach (string adapterID in pendingsIDs)
  {
      FileAdapter adapter = FileAdapter.LoadFileAdapter(profile, new Guid(adapterID), ref errMsg);
      if (adapter != null)
      {
          DataRow dr = dt.NewRow();
          CheckBox cb = new CheckBox();
          cb.Checked = FileAdapter.IsReserved;
          cb.ID = "CheckSelect";
          dr["CheckSelect"] = cb; &lt;&lt;&lt;---?????
          dr["FilePath"] = adapter.GetPartialFilePath();
          dr["AttachmentID"] = adapter.ObjectID.ToString("N");
          dt.Rows.Add(dr);    
      }
  }
  
  AttachedFilesGridView.DataSource = dt;
  AttachedFilesGridView.DataBind();
  </code></pre>
  
  <p>The problem is this:</p>
  
  <p>The "FilePath" and "AttachmentID" fields are being set correctly in the grid, however, the CheckBox control is never set correctly; it is always unchecked.</p>
  
  <p>My question:</p>
  
  <p>How do I get this CheckBox field set from C# as I'm creating the new row?</p>
  
  <p>P.S. I am not sure if I am creating the row correctly in the first place.</p>