title: How to check checkbox based on database values in C#
body: <p>I have created Checkbox list and Button to store Checked Values in  ASP.Net application using C# as follows,</p>
  
  <pre><code> &lt;asp:CheckBoxList ID="CheckBoxList1" runat="server" Width="120px"&gt;
           &lt;/asp:CheckBoxList&gt;
  &lt;asp:Button ID="AddCheckedData" Height="25px" runat="server" Text="Add Checked Data"  
                                                  onclick="AddCheckedData_Click"/&gt;
  </code></pre>
  
  <p>I have binded CheckBoxList in Code behind as,</p>
  
  <pre><code>public void bindchecklist()
      {
          B.SFS_CODE = Convert.ToInt32(TxtHQCode.Text);
          B.id = 7; //tblparent AND tblchild
          ds8 = A.DATA8(B);
          CheckBoxList1.DataSource = ds8.Tables[0];
          CheckBoxList1.DataTextField = "EMP_NAME";
          CheckBoxList1.DataValueField = "EMP_CODE";
          CheckBoxList1.DataBind();
      }
  </code></pre>
  
  <p>And the button click event to store the selected values in DataBase as follows,</p>
  
  <pre><code>string selemployee = string.Empty;
  foreach (ListItem item in CheckBoxList1.Items)
  {
  if (item.Selected)
  {
  selemployee = item.Value;
  B.id = 8;//insert into DCR_CHECKED
  B.Emp_Code = selemployee;
  ds8 = A.DATA8(B);
  }
  }
  </code></pre>
  
  <p>Now,i have another button to edit the CheckBoxList Selection.Now,i want to retrieve the data from database and check the checkboxes which are availabe(inserted checkbox values in databse when click save button) in DataBase when Clicking Edit Button.</p>