title: CheckBoxList loop not working
body: <p>I'm trying to select values in a <code>CheckBoxList</code> control based on a data source. I have five items in the <code>CheckBoxList</code> and three items in the data source, but in the loop I only get one item selected.</p>
  
  <pre><code>if (ddlUserId.SelectedIndex != 0)
  {
     RoleDetails rd;
     rd = CatalogAccess.GetSingleUserRole(ddlUserId.SelectedValue.ToString());
  
     for (int i = 0; i &lt; cblRoles.Items.Count; i++)
     {
        cblRoles.Items.FindByValue(rd.RoleID.ToString()).Selected = true;
     }
  }
  </code></pre>
  
  <p>I tried this, but it still selects only one item:</p>
  
  <pre><code>RoleDetails rd;
  
  for (int i = 0; i &lt; cblRoles.Items.Count; i++)
  {            
     rd = CatalogAccess.GetSingleUserRole(ddlUserId.SelectedValue.ToString());
  
     if (cblRoles.Items[i].Value == rd.RoleID.ToString())
        cblRoles.Items[i].Selected = true;
  }
  </code></pre>
  
  <p>CheckboxList bind code</p>
  
  <pre><code>  cblRoles.DataSource = CatalogAccess.GetRoles();
    cblRoles.DataTextField = "RoleDetails";
    cblRoles.DataValueField = "RoleId";
    cblRoles.DataBind();
  </code></pre>