title: Determining which items are selected in CheckBoxList using Request.Form
body: <p>Using the approach shown in the question <a href="https://stackoverflow.com/questions/6329552/how-to-know-which-value-items-where-selected-from-a-checkboxlist-using-request-f">here</a>, I am able to get the selected items values from my <code>CheckBoxList</code>:</p>
  
  <pre><code>var selectedCheckBoxItems = from key in Request.Form.AllKeys
                          where key.Contains(cbl.ID)
                          select Request.Form.Get(key);
  </code></pre>
  
  <p>I can then iterate over the results:</p>
  
  <pre><code>foreach (var item in selectedCheckBoxItems)
  {
  
  }
  </code></pre>
  
  <p>The problem is that <code>item</code> is just the posted value, which for a checkbox, is simply the string "on".  </p>
  
  <p><a href="https://i.stack.imgur.com/2qqHM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2qqHM.png" alt="on"></a></p>
  
  <p>I need to be able to determine which item is "on", either by index or some other method.</p>
  
  <p><strong>Question:</strong>  How do I determine which items in the <code>CheckBoxList</code> are selected, using <code>Request.Form</code> ?</p>
  
  <p>Here is my CheckBoxList definition:</p>
  
  <pre><code>&lt;asp:CheckBoxList runat="server" ID="cblAnimalType" SelectionMode="Multiple" DataTextField="OptionText" DataValueField="OptionId"  AutoPostBack="True"/&gt;
  </code></pre>
  
  <p>Items are added to the list from code behind:</p>
  
  <pre><code>DataTable dt = GetData(SqlGetListOptions, paramList);
  cbl.DataSource = dt;
  cbl.DataBind();
  </code></pre>
  
  <p>The other important thing to know is that <code>ViewStateMode="Disabled"</code>, so I must use <code>Request.Form</code> to get the selected items.</p>
  
  <hr>
  
  <p>In response to a comment, here is how the HTML for the CheckBoxList renders:</p>
  
  <p><a href="https://i.stack.imgur.com/1TYVF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1TYVF.png" alt="html"></a></p>
  
  <hr>
  
  <p>@Leopard pointed out that he sees values rendered in the HTML which is not occurring in my situation.  AdamE's answer to <a href="https://stackoverflow.com/questions/180245/where-are-the-datavaluefield-values-for-a-checkboxlist-stored">this question</a> explains why.  I have the following line in web.config:</p>
  
  <pre><code>&lt;pages validateRequest="false" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"&gt;
  </code></pre>
  
  <p>which explains why I see "on" instead of the actual value of the selected items.  I am not able to just yank the compatibility out of web.config without verifying it won't break something else, but it appears that if that setting is safe to remove, the checkbox list values will be accessible from codebehind.</p>