title: set checkbox in gridview based on datatable value
body: <p>I have a gridview control with a checkbox field and several bound fields.  The checkbox field does not directly map to a field in the database.  Rather, i want to read a value from a field in the database and "check" some of the checkboxes.</p>
  
  <p>For example, given the following data from the database -> datatable</p>
  
  <pre>
          PROCESSED   NAME             DATE            
              Y       Mickey Mouse     11/15/2011
              N       Donald Duck      4/01/2012
              Y       James Bond       5/02/2011
  </pre>
  
  <p>I would like the gridview to display a checkbox and set the value of boxes to UNCHECKED where PROCESSED = N and for PROCESSED = Y either have an uneditable checkbox or no checkbox at all.</p>
  
  <pre>
          PROCESSED   NAME             DATE            
             [/]       Mickey Mouse     11/15/2011
             [ ]       Donald Duck      4/01/2012
             [/]       James Bond       5/02/2011
  
  </pre>
  
  <p>To populate the gridview, a SQL stmt is run against a database, and the result of the SQL query is stored in a datatable.  Before binding the datatable to the gridview, i would like to check the "processed" field and set the checkbox based on that value.</p>
  
  <p>Here is the gridview control (shortened for clarity):</p>
  
  <pre><code>&lt;asp:GridView ID="gridview_all_applicants" runat="server" AllowPaging="True"&gt;
          &lt;Columns&gt;
            &lt;asp:TemplateField HeaderText="Complete"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:CheckBox ID="process_flag" runat="server" /&gt;
                  &lt;/ItemTemplate&gt;
            &lt;/asp:TemplateField&gt;
            &lt;asp:BoundField DataField="lastname" HeaderText="Last Name" ReadOnly="True"  SortExpression="lastname" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here is what i have so far in the code behind</p>
  
  <pre><code> SqlCommand cmd = new SqlCommand(sql query here);
   SqlDataAdapter da = new SqlDataAdapter();
   DataTable dt = new DataTable();
   da.SelectCommand = cmd;
   // Save results of select statement into a datatable
   da.Fill(dt);
   foreach (DataRow r in dt.Rows)
   {
          // do some processing of data returned from query
          // read the char value from the returned data and set checkbox
  
               procflag = r["process_flag"].ToString().ToLower();
               CheckBox chkbox = new CheckBox();
               if (procflag == null || procflag == "n")
               {
                  // SET CHECKBOX TO "NOT CHECKED"        
  
                }
                else
                {
                   // SET CHECKBOX TO "CHECKED" AND MAKE IT UNCLICKABLE
                   // ----OR---- DO NOT DISPLAY CHECKBOX AT ALL.
  
                 }
       } // end for each
  
  
            gridview_all_applicants.DataSource = dt;
            gridview_all_applicants.DataBind(); 
  </code></pre>
  
  <p>any help is greatly appreciated.</p>