title: identify selected checkboxes in asp listview object
body: <p>I have been trying to understand the ListView object in ASP but I'm unable to programmatically get the selected checkboxes or iterate through them.  Below are the two methods I'm seeing posted the most here on SO, but so far everything I've tried hasn't seemed to work for me.</p>
  
  <p>Any help would greatly be appreciated.</p>
  
  <p><strong>.ASPX Page</strong></p>
  
  <pre><code>&lt;asp:ListView ID="courseListView" runat="server"&gt;
  
  &lt;LayoutTemplate&gt;
  &lt;table&gt;&lt;asp:PlaceHolder runat="server" ID="itemPlaceholder"&gt;      
  &lt;/asp:PlaceHolder&gt;&lt;/table&gt;
  &lt;/LayoutTemplate&gt;
  
  &lt;ItemTemplate&gt;
            &lt;tr&gt;
            &lt;td&gt;&lt;asp:CheckBox ID="courseIdchk" Text='&lt;%# Eval("CourseId") %&gt;' runat="server" /&gt;&lt;/td&gt;
            &lt;td&gt;&lt;asp:Label ID="courseTitleLbl" Text='&lt;%# Eval("title") %&gt;' runat="server" /&gt;&lt;/td&gt;
            &lt;/tr&gt;
  &lt;/ItemTemplate&gt;
  &lt;/asp:ListView&gt;
  </code></pre>
  
  <p><strong>.CS Code Behind</strong></p>
  
  <pre><code>//Method #1
        string result = string.Join(", ",    courseListView.Controls.OfType&lt;CheckBox&gt;()
                        .Select(chk =&gt; chk.Text));
        string result = "";
  
    //Method #2
    foreach (CheckBox ctrl in courseListView.Controls.OfType&lt;CheckBox&gt;())
    {
        result2 += ctrl.Text;
    }
  
    Response.Write("&lt;p&gt;The result is " + result);
    Response.Write("&lt;p&gt;The result is " + result2);
    Response.End();
  </code></pre>