title: ListView containing CheckBoxList - Selected items not showing as checked
body: <p>I have a <code>ListView</code> with an <code>EditItemTemplate</code> that calls a method <code>onItemEditing</code>.</p>
  
  <p>Within my <code>ListView</code> I have a <code>CheckBoxList</code> bound using <code>LINQ</code>.</p>
  
  <p>In my <code>onItemEditing</code> method, I'm trying to check certain <code>CheckBoxes</code> if they are present in a look up table that links users with sectors.</p>
  
  <p>However, when I load the <code>EditItemTemplate</code> none of the <code>CheckBoxes</code> are checked even though I've set them as selected in the <code>onItemEditing</code> method. </p>
  
  <p>Here's the Method:</p>
  
  <pre><code>protected void onItemEditing(object sender, ListViewEditEventArgs e)
  {
      ListView1.EditIndex = e.NewEditIndex;
      ListView1.DataBind();
  
      int regId = Convert.ToInt32(((Label)ListView1.Items[e.NewEditIndex].FindControl("LblRegId")).Text);
      CheckBoxList cbl = (CheckBoxList) ListView1.Items[e.NewEditIndex].FindControl("chkLstSectors");
  
  //test to see if forcing first check box to be selected works - doesn't work
      cbl.Items[0].Selected = true;
  
      SqlConnection objConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DaresburyConnectionString"].ToString());
      SqlCommand objCmd = new SqlCommand("select * from register_sectors where register_id= " + regId, objConn);
      objConn.Open();
  
      SqlDataReader objReader = objCmd.ExecuteReader();
  
      if (objReader != null)
      {
          while (objReader.Read())
          {
              ListItem currentCheckBox = cbl.Items.FindByValue(objReader["sector_id"].ToString());
              if (currentCheckBox != null)
              {
                  currentCheckBox.Selected = true;
              }
          }
      }
  }
  </code></pre>
  
  <p>Any ideas how to get around this?</p>