• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 726
  • Last Modified:

Checklistbox - clear item

How can I clear all selected items in Checklistbox? I am using VS2005.


    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

        For Each item As ListItem In Me.CheckBoxList1.Items

            If item.Selected Then

                Response.Write(item.ToString & " ")


            End If



        Next

        Me.CheckBoxList1.SelectedItem = -1  ???? error


 
    End Sub
0
VBdotnet2005
Asked:
VBdotnet2005
  • 2
1 Solution
 
j-w-thomasCommented:
You have to use a loop to clear each one individually.


for i = 0 to Me.CheckBoxList.Items.Count - 1
     
     Me.CheckBoxList.Item(i).Selected = false

next

John
0
 
j-w-thomasCommented:
Sorry correct that, it should be "...Items(i)..."

Me.CheckBoxList.Items(i).Selected = false
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now