title: I need to populate my gridview after I select a checkbox from checkboxlist
body: <p>I need to populate my gridview after I select a checkbox from checkboxlist. I'm trying to use a loop, I also need to hide the gridview if the user unchecks the checkbox. Im useing a sql statement to pull the data. The sql should pull whatever data is associated with the checked box
      'Shows Books from selected Category
      Protected Sub chkbListControl_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles chkListControl.SelectedIndexChanged</p>
  
  <pre><code>    Dim sqlChecked As String = "select * " _
                                &amp; "from Books, Categories " _
                                &amp; "where Categories.CategoryCode=Books.CategoryCode " _
                                &amp; "order by Title;"
  
      Dim sqlUnChecked As String = "select * from Books where Categories.CategoryCode=Books.CategoryCode;"
  
      Dim selectedIndex As Integer = chkListControl.SelectedIndex
      Dim i As Integer
  
      If (selectedIndex &lt;&gt; -1) Then
  
          For i = 0 To chkListControl.Items.Count - 1
  
              If chkListControl.Items(i).Selected Then
  
                  gvwBookList.DataSource = ReturnTable(sqlChecked)
                  gvwBookList.DataBind()
  
              Else
  
                  gvwBookList.DataSource = ReturnTable(sqlUnChecked)
                  gvwBookList.DataBind()
                  gvwBookList.Visible = False
  
              End If
          Next
      End If
  
  End Sub
  </code></pre>