title: convert column in Gridview to checkboxes
body: <p>I have a gridview that displays a list of items and if they are checked or not. In the database the value is a boolean value. But in the GridView the column is displaying as true or false. How do I change it a checkbox instead of true/false. </p>
  
  <pre><code>&lt;asp:BoundField DataField="Checked" HeaderText="Checked"&gt;&lt;/asp:BoundField&gt;
  </code></pre>
  
  <p>Code behind:</p>
  
  <pre><code> protected void gvCVRTDetails_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              lookupCVRT work = (lookupCVRT)e.Row.DataItem;
              GridView gv = sender as GridView;
  
              e.Row.Attributes.Add("ID", "gvCVRTDetails_" + work.ID);
              e.Row.Cells[0].Attributes.Add("onclick", "event.stopPropagation();");
  
              HtmlGenericControl lnkShowHide = (HtmlGenericControl)e.Row.FindControl("lnkShowHide");
              HyperLink ChecklistItem = (HyperLink)e.Row.FindControl("ID");
  
  
          }
      }  
  </code></pre>
  
  <p>I found an example of this for a DataGrid:</p>
  
  <pre><code>int count = 1;
              foreach (TableCell c in e.Item.Cells)
              {
                  bool b = Convert.ToBoolean(((DataRowView)e.Item.DataItem).Row["IsActive"]);
  
                  if (count == e.Item.Cells.Count)
                  {
                      c.Text = "&lt;input type=\"checkbox\" " + ((b) ? "checked" : "") + "/&gt;";
                  }
                  count++;
              }
  </code></pre>
  
  <p>But since I am using a gridview I tried changing the code to this:</p>
  
  <pre><code>int count = 1;
              foreach (TableCell c in e.Row.Cells)
              {
                  bool b = Convert.ToBoolean(((GridViewRow)e.Row.DataItem).Row["Checked"]); //error
  
                  if (count == e.Row.Cells.Count)
                  {
                      c.Text = "&lt;input type=\"checkbox\" " + ((b) ? "checked" : "") + "/&gt;";
                  }
                  count++;
              }
  </code></pre>
  
  <p>But I am getting the error: </p>
  
  <blockquote>
    <p>'System.Web.UI.WebControls.GridViewRow' does not contain a definition
    for 'Row' and no extension method 'Row' accepting a first argument of
    type 'System.Web.UI.WebControls.GridViewRow' could be found (are you
    missing a using directive or an assembly reference?)</p>
  </blockquote>