title: how to check selected item in Check Box List (generated from code)
body: <p>i have I have an ASP.NET / VB application 
  i need check on selected item in check box list but the checkbox is dynamically from code behind</p>
  
  <pre><code>&lt;asp:Panel ID="panel1" runat="server"&gt;
      &lt;asp:Button ID="Button1" runat="server" Text="Save" /&gt;
      &lt;asp:Label ID="lbl_Selected_Items" runat="server" Text=""&gt;&lt;/asp:Label&gt;
  &lt;/asp:Panel&gt;
  </code></pre>
  
  <p>code behind 
  page load</p>
  
  <pre><code>Dim CheckBoxList As New CheckBoxList
              pagerview.Controls.Add(CheckBoxList)
              ...est
  </code></pre>
  
  <p>Button1 Click event</p>
  
  <pre><code>Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  Dim CheckBoxList1 As CheckBoxList = CType(Me.FindControl("CheckBoxList"), CheckBoxList)
  Dim sCheckedValue As String = ""
  For Each oItem As ListItem In CheckBoxList1.Items
      If oItem.Selected Then
          If sCheckedValue = "" Then
              sCheckedValue = ("Selected Value : " + oItem.Value &amp; " Selected Text: ") + oItem.Text
          Else
              sCheckedValue += ("&lt;br/&gt;Selected Value : " + oItem.Value &amp; " Selected Text: ") + oItem.Text
          End If
      End If
  Next
  lbl_Selected_Items.Text = sCheckedValue
  </code></pre>
  
  <p>error text : null reference exception object reference not set to an instance of an object –
    <a href="http://i.stack.imgur.com/vzo0J.png" rel="nofollow">Error </a></p>