title: How to modify this checkbox inside the GridView?
body: <p>I have the following database design:</p>
  
  <pre><code>Employee Table: Username, Name, JobTitle, BadgeNo, IsActive, DivisionCode
  Divisions Table: SapCode, DivisionShortcut
  </code></pre>
  
  <p>And I have a GridView that I am using it to add, delete and update/edit the employees information. This information is employee Username, Name, BadgeNo, JobTitle, IsActive and the DivisionShortcut. <strong><em>IsActive is a flag that indicates if the employee is available or in an assignment</em></strong>. I made it as a checkbox and the column should show two values; Active and Inactive. In the Edit mode, the Checkbox will be displayed. If it is checked, then it means the employee is avaiable, otherwise it is inactive. </p>
  
  <p>I wrote the code and everything works fine, but now I am facing two problems and I don't know how to make them work with my code.</p>
  
  <ol>
  <li>The GridView shows True or False instead of Active and Inactive and
  I don't know why.</li>
  <li>In the Edit mode, the checkbox will be displayed and the values (Active or Inactive) will be displayed besides to it and it shouldn't be displayed. I just want the checkbox to be displayed.</li>
  </ol>
  
  <p><strong>So how to modify them?</strong></p>
  
  <p><img src="https://i.stack.imgur.com/UyuT9.png" alt="enter image description here"></p>
  
  <p>ASP.NET code:</p>
  
  <pre><code>&lt;%-- GridView for User Management Subsystem --%&gt;
          &lt;asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
              AutoGenerateColumns="False" DataKeyNames="Username" 
              DataSourceID="SqlDataSource1" BorderWidth="1px" BackColor="#DEBA84" 
               CellPadding="3" CellSpacing="2" BorderStyle="None" 
               BorderColor="#DEBA84"&gt;
              &lt;FooterStyle ForeColor="#8C4510" 
                BackColor="#F7DFB5"&gt;&lt;/FooterStyle&gt;
              &lt;PagerStyle ForeColor="#8C4510" 
                HorizontalAlign="Center"&gt;&lt;/PagerStyle&gt;
              &lt;HeaderStyle ForeColor="White" Font-Bold="True" 
                BackColor="#A55129"&gt;&lt;/HeaderStyle&gt;
              &lt;Columns&gt;
                  &lt;asp:CommandField ButtonType="Image" ShowEditButton="true" ShowCancelButton="true"
                                  EditImageUrl="Images/icons/edit24.png" UpdateImageUrl="Images/icons/update24.png" 
                                  CancelImageUrl="Images/icons/cancel324.png" /&gt;
  
                  &lt;asp:TemplateField HeaderText="Division"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;%# Eval("DivisionShortcut")%&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:DropDownList ID="DivisionsList" runat="server" DataSourceID="DivisionsListDataSource"
                                            DataTextField="DivisionShortcut" DataValueField="SapCode"
                                            SelectedValue='&lt;%# Bind("DivisionCode")%&gt;'&gt;
                          &lt;/asp:DropDownList&gt;
                      &lt;/EditItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  
                  &lt;asp:BoundField DataField="Username" HeaderText="Network ID" ReadOnly="True" 
                      SortExpression="Username" /&gt;
  
                  &lt;asp:TemplateField HeaderText="Name"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;%# Eval("Name")%&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:TextBox ID="txtEmployeeName" runat="server" Text='&lt;%# Bind("Name")%&gt;' /&gt;
                      &lt;/EditItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  
                  &lt;asp:TemplateField HeaderText="Job Title"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;%# Eval("JobTitle")%&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:TextBox ID="txtJobTitle" runat="server" Text='&lt;%# Bind("JobTitle")%&gt;' /&gt;
                      &lt;/EditItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  
                  &lt;asp:TemplateField HeaderText="Badge No."&gt;
                      &lt;ItemTemplate&gt;
                          &lt;%# Eval("BadgeNo")%&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:TextBox ID="txtBadgeNo" runat="server" Text='&lt;%# Bind("BadgeNo")%&gt;' /&gt;
                      &lt;/EditItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  
                  &lt;asp:TemplateField HeaderText="Is Active?"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;%# Eval("IsActive")%&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:CheckBox ID="isActive" runat="server" 
                                        AutoPostBack="true" OnCheckedChanged="isActive_OnCheckedChanged"
                                        Checked='&lt;%# Convert.ToBoolean(Eval("IsActive")) %&gt;'
                                        Text='&lt;%# Eval("IsActive").ToString().Equals("True") ? " Active " : " Inactive " %&gt;'/&gt;
                      &lt;/EditItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  
                  &lt;asp:TemplateField HeaderText="Delete?"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;span onclick="return confirm('Are you sure to Delete the record?')"&gt;
                              &lt;asp:ImageButton ID="lnkB" runat="server" ImageUrl="Images/icons/delete24.png" CommandName="Delete" /&gt;
                          &lt;/span&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
              &lt;/Columns&gt;
          &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Code-behind:</p>
  
  <pre><code>//for updating the (IsActive) column using checkbox inside the GridView
      protected void isActive_OnCheckedChanged(object sender, EventArgs e)
      {
          CheckBox chkStatus = (CheckBox)sender;
          GridViewRow gvrow = (GridViewRow)chkStatus.NamingContainer;
  
          //Get the ID which is the NetworkID of the employee
          string username = gvrow.Cells[2].Text;
          bool status = chkStatus.Checked;
  
          string connString = ConfigurationManager.ConnectionStrings["UsersInfoDBConnectionString"].ConnectionString;
          SqlConnection conn = new SqlConnection(connString);
  
          string updateIsActive = "UPDATE Employee SET IsActive = @IsActive WHERE Username = @Username";
  
          SqlCommand cmd = new SqlCommand(updateIsActive, conn);
  
          cmd.Parameters.AddWithValue("@IsActive", status);
          cmd.Parameters.AddWithValue("@Username", username);
  
          try
          {
              conn.Open();
              cmd.ExecuteNonQuery();
              conn.Close();
          }
          catch (SqlException se)
          {
              throw se;
          }
          finally
          {
              cmd.Dispose();
              conn.Close();
              conn.Dispose();
          }
      }
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I update my code as following:
  ASP.NET Code:</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
              AutoGenerateColumns="False" DataKeyNames="Username" 
              DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound" BorderWidth="1px" BackColor="#DEBA84" 
               CellPadding="3" CellSpacing="2" BorderStyle="None" 
               BorderColor="#DEBA84"&gt;
              &lt;FooterStyle ForeColor="#8C4510" 
                BackColor="#F7DFB5"&gt;&lt;/FooterStyle&gt;
              &lt;PagerStyle ForeColor="#8C4510" 
                HorizontalAlign="Center"&gt;&lt;/PagerStyle&gt;
              &lt;HeaderStyle ForeColor="White" Font-Bold="True" 
                BackColor="#A55129"&gt;&lt;/HeaderStyle&gt;
              &lt;Columns&gt;
                  &lt;asp:CommandField ButtonType="Image" ShowEditButton="true" ShowCancelButton="true"
                                  EditImageUrl="Images/icons/edit24.png" UpdateImageUrl="Images/icons/update24.png" 
                                  CancelImageUrl="Images/icons/cancel324.png" /&gt;
  
                  &lt;asp:TemplateField HeaderText="Division"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;%# Eval("DivisionShortcut")%&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:DropDownList ID="DivisionsList" runat="server" DataSourceID="DivisionsListDataSource"
                                            DataTextField="DivisionShortcut" DataValueField="SapCode"
                                            SelectedValue='&lt;%# Bind("DivisionCode")%&gt;'&gt;
                          &lt;/asp:DropDownList&gt;
                      &lt;/EditItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  
                  &lt;asp:BoundField DataField="Username" HeaderText="Network ID" ReadOnly="True" 
                      SortExpression="Username" /&gt;
  
                  &lt;asp:TemplateField HeaderText="Name"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;%# Eval("Name")%&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:TextBox ID="txtEmployeeName" runat="server" Text='&lt;%# Bind("Name")%&gt;' /&gt;
                      &lt;/EditItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  
                  &lt;asp:TemplateField HeaderText="Job Title"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;%# Eval("JobTitle")%&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:TextBox ID="txtJobTitle" runat="server" Text='&lt;%# Bind("JobTitle")%&gt;' /&gt;
                      &lt;/EditItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  
                  &lt;asp:TemplateField HeaderText="Badge No."&gt;
                      &lt;ItemTemplate&gt;
                          &lt;%# Eval("BadgeNo")%&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:TextBox ID="txtBadgeNo" runat="server" Text='&lt;%# Bind("BadgeNo")%&gt;' /&gt;
                      &lt;/EditItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  
                  &lt;asp:TemplateField HeaderText="Is Active?"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:Label ID="lblIsActive" runat="server" Text='&lt;%# Eval("IsActive")%&gt;'&gt;&lt;/asp:Label&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:CheckBox ID="isActive" runat="server" 
                                        AutoPostBack="true" OnCheckedChanged="isActive_OnCheckedChanged"
                                        Checked='&lt;%# Convert.ToBoolean(Eval("IsActive")) %&gt;'
                                        Text='&lt;%# Eval("IsActive")%&gt;'/&gt;
                      &lt;/EditItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  
                  &lt;asp:TemplateField HeaderText="Delete?"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;span onclick="return confirm('Are you sure to Delete the record?')"&gt;
                              &lt;asp:ImageButton ID="lnkB" runat="server" ImageUrl="Images/icons/delete24.png" CommandName="Delete" /&gt;
                          &lt;/span&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
              &lt;/Columns&gt;
          &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Code-Behind:</p>
  
  <pre><code>//For showing Active or Inactive in the IsActive column instead of True or False
      protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              //Here we will select the IsActive column and modify its text
              Label isActive = new Label();
              isActive = (Label)e.Row.FindControl("lblIsActive");
              //Now, after getting the reference, we can set its text
              isActive.Text = "Active or Inactive";
  
              // First check Checkedbox is check or not, if not make it grey
              //if (e.Row.Cells[6].Text == "False")
              //    GridView1.BackColor = Color.Gray;
  
          }
      }
  </code></pre>
  
  <p>And I am getting the following error and I don't know why:
  <img src="https://i.stack.imgur.com/gq8EM.png" alt="enter image description here"></p>