title: Get bit value from database and show in CheckBox in GridView
body: <p>How do I to get a bit value from a database table and show its value in a  checkbox (e.g if value is TRUE then it's checked, otherwise checkbox is unchecked) in a GridView? Also, how do I get the checkbox value and insert it into a database table which has a "bit" datatype column? </p>
  
  <p>Here is my table <a href="http://hostthenpost.org/uploads/d18c993aadfe7a54fdb9e9b626cbde29.png" rel="nofollow">image</a></p>
  
  <p>And here is my GridView <a href="http://hostthenpost.org/uploads/d0c8e23d588fffb710d34a961f313069.png" rel="nofollow">image</a></p>
  
  <p>Here is my .CS code:</p>
  
  <pre><code>public void lbinssert(Object sender,EventArgs e)
  {
      sql.InsertParameters["ColumnName"].DefaultValue =
          ((TextBox)GridView1.FooterRow.FindControl("txtColName")).Text;
  
      sql.InsertParameters["Dtype"].DefaultValue =
          ((DropDownList)GridView1.FooterRow.FindControl("DropDownList2")).Text;
  
      sql.InsertParameters["id"].DefaultValue =
          ((DropDownList)GridView1.FooterRow.FindControl("DropDownList2")).Text;
  
      sql.InsertParameters["null"].DefaultValue =
          ((CheckBox)GridView1.FooterRow.FindControl("nulll")).Text;
  
      sql.InsertParameters["primary"].DefaultValue = 
          ((CheckBox)GridView1.FooterRow.FindControl("primary")).Text;
  
      sql.Insert();
  }
  </code></pre>
  
  <p>Here is my .aspx code:</p>
  
  <pre><code>        &lt;asp:TemplateField HeaderText="Column_Name" SortExpression="Column_Name"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:TextBox ID="txtName" runat="server" Text='&lt;%#Bind("Column_Name")%&gt;'&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:RequiredFieldValidator Text="*" ID="colname" ControlToValidate="txtName" runat="server" ErrorMessage="Column Name is Required" ForeColor="Red"&gt;&lt;/asp:RequiredFieldValidator&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                 &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Bind("Column_Name") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;asp:TextBox ID="txtColName" runat="server"&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:RequiredFieldValidator ValidationGroup="INSERT" Text="*" ID="insertcolname" ControlToValidate="txtColName"runat="server" ErrorMessage="Column Name is Required" ForeColor="Red"&gt;&lt;/asp:RequiredFieldValidator&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Data_Type" SortExpression="Data_Type"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='&lt;%# Bind("Data_Type") %&gt;'&gt;
                      &lt;asp:ListItem&gt;Select Datatype&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;int&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Float&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Varchar(50)&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Varchar(100)&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;double&lt;/asp:ListItem&gt;
                  &lt;/asp:DropDownList&gt;
                  &lt;asp:RequiredFieldValidator ID="datatype" ControlToValidate="DropDownList1"
                      runat="server" ErrorMessage="Data Type is Required" ForeColor="Red" InitialValue="Select Datatype"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="Label2" runat="server" Text='&lt;%# Bind("Data_Type") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;asp:DropDownList ID="DropDownList2" runat="server"&gt;
                      &lt;asp:ListItem&gt;Select Datatype&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;int&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Float&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Varchar(50)&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Varchar(100)&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;double&lt;/asp:ListItem&gt;
                  &lt;/asp:DropDownList&gt;
                  &lt;asp:RequiredFieldValidator ValidationGroup="INSERT" Text="*"  ID="datatype" ControlToValidate="DropDownList2"
                      runat="server" ErrorMessage="Data Type is Required" ForeColor="Red" InitialValue="Select Datatype"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Allow_Null_" SortExpression="Allow_Null_"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:CheckBox ID="CheckBox1" runat="server" Checked='&lt;%# DataBinder.Eval(Container.DataItem,"Allow_Null_").ToString().Equals("1") %&gt;'/&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:CheckBox ID="CheckBox1" runat="server" Checked='&lt;%# DataBinder.Eval(Container.DataItem,"Allow_Null_").ToString().Equals("1") %&gt;' enabled="false" /&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;asp:CheckBox ID="nulll" runat="server" /&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Primary_Key_" SortExpression="Primary_Key_"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:CheckBox ID="CheckBox2" runat="server" Checked='&lt;%# DataBinder.Eval(Container.DataItem,"Primary_Key_").ToString().Equals("1") %&gt;' /&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:CheckBox ID="CheckBox2" runat="server" 
                      Checked='&lt;%# DataBinder.Eval(Container.DataItem,"Primary_Key_").ToString().Equals("1") %&gt;' Enabled="false" /&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;asp:CheckBox ID="primary" runat="server" /&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Date" SortExpression="Date"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:TextBox ID="TextBox3" runat="server" Text='&lt;%# Bind("Date") %&gt;'&gt;&lt;/asp:TextBox&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="Label3" runat="server" Text='&lt;%# Bind("Date") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;asp:LinkButton ValidationGroup="INSERT" OnClick="lbinssert" ID="lblInsert" runat="server"&gt;Insert&lt;/asp:LinkButton&gt;
              &lt;/FooterTemplate&gt; 
          &lt;/asp:TemplateField&gt;
          &lt;asp:CommandField ShowEditButton="True" /&gt;
          &lt;asp:CommandField ShowDeleteButton="True" /&gt;
      &lt;/Columns&gt;
      &lt;FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" /&gt;
      &lt;HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" /&gt;
      &lt;PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" /&gt;
      &lt;RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" /&gt;
      &lt;SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" /&gt;
      &lt;SortedAscendingCellStyle BackColor="#FFF1D4" /&gt;
      &lt;SortedAscendingHeaderStyle BackColor="#B95C30" /&gt;
      &lt;SortedDescendingCellStyle BackColor="#F1E5CE" /&gt;
      &lt;SortedDescendingHeaderStyle BackColor="#93451F" /&gt;
  &lt;/asp:GridView&gt;
  
  &lt;asp:ValidationSummary ValidationGroup="INSERT" ID="ValidationSummary1" ForeColor="Red"
      runat="server" Height="54px" style="margin-left: 140px" /&gt;
  
  &lt;asp:ValidationSummary ID="ValidationSummary2" ForeColor="Red" runat="server" 
      style="margin-left: 161px" /&gt;
  
  &lt;asp:SqlDataSource ID="sql" runat="server" 
      ConnectionString="&lt;%$ ConnectionStrings:db_compilerConnectionString %&gt;"
      SelectCommand="SELECT [Column_Name], [Data_Type], [Allow_Null_], [Primary_Key_], [Date] FROM [tbl_field]"
      DeleteCommand="DELETE * FROM [tbl_field] WHERE [Field_id]=@field" InsertCommand="INSERT INTO [tbl_field] ([Column_Name],[Data_Type],[Database_id],[Allow_Null_],[Primary_Key_])Values (@ColumnName,@Dtype,@id,@null,@primary)"
      UpdateCommand="UPDATE [tbl_field] SET [Column_Name]=@ColumnName,[Data_Type]=@Dtype,[Database_id]=@id,[Allow_Null_]=@null,[Primary_Key_]=@primary"&gt;
      &lt;DeleteParameters&gt;
          &lt;asp:Parameter Name="field" Type="Int32" /&gt;
      &lt;/DeleteParameters&gt;
      &lt;InsertParameters&gt;
          &lt;asp:Parameter Name="ColumnName" Type="String" /&gt;
          &lt;asp:Parameter Name="Dtype" Type="String" /&gt;
          &lt;asp:Parameter Name="id" Type="String" /&gt;
          &lt;asp:Parameter Name="null" Type="Boolean" /&gt;
          &lt;asp:Parameter Name="primary" Type="Boolean" /&gt;
      &lt;/InsertParameters&gt;
      &lt;UpdateParameters&gt;
          &lt;asp:Parameter Name="ColumnName" Type="String" /&gt;
          &lt;asp:Parameter Name="Dtype" Type="String" /&gt;
          &lt;asp:Parameter Name="id" Type="String" /&gt;
          &lt;asp:Parameter Name="null" Type="Boolean"/&gt;
          &lt;asp:Parameter Name="primary" Type="Boolean" /&gt; 
      &lt;/UpdateParameters&gt;
  &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>The value is inserted into the database, but "Allow_Null_" and "Primary_Key_" are showing "NULL". Please tell me how can I resolve this issue.</p>