Dynamically Check And Uncheck Checkbox Based On DB Value In Gridview

Create a GridView with checkbox.
  1. <asp:GridView ID="Gridview" runat="server" Font-Size="8pt"  
  2.             PageSize="200" Width="880px" AutoGenerateColumns="False">  
  3.             <Columns>  
  4.                 <asp:TemplateField>  
  5.                     <HeaderTemplate>  
  6.                         <asp:CheckBox ID="chkHeader" Text="Select All" runat="server" />  
  7.                     </HeaderTemplate>  
  8.                     <ItemTemplate>  
  9.                         <asp:CheckBox ID="chkChild" runat="server"  Checked='<%# Eval("PROCESSED").ToString().Equals("1") %>' Enabled='<%# !Eval("PROCESSED").ToString().Equals("1") %>'/>  
  10.                     </ItemTemplate>  
  11.                 </asp:TemplateField>             
  12.             </Columns>  
  13.         </asp:GridView>  
Get the data from the database, the field from the database to check the checkbox should be 1 or 0.
 
DB Table data
 
PROCESSED (HEADER)
1
1
 
DataField "PROCESSED" should be 1 or 0 (boolean),
  1. Checked='<%# Eval("PROCESSED").ToString().Equals("1") %>'  
The above GridView code will check the checkbox if the value from the PROCESSED field in DB is 1 else if the PROCESSED value is other than 1 the checkbox will be unchecked,
  1. Enabled='<%# !Eval("PROCESSED").ToString().Equals("1") %>'  
This code will help us to enable or disable the text box. In the above mentioned code, if the PROCESSED is 1, checkbox will be disabled else the checkboc will be enable.