We help IT Professionals succeed at work.

DropDownList Remove Items

eciabattari
eciabattari asked
on
2,391 Views
Last Modified: 2008-07-08
Hi,

Trying to remove items from a dropdownlist.  I've tried the following but neither have worked for me.

    Private Sub RemoveItems()
       Dim i As Integer
        For i = 0 To DropDownList2.Items.Count
                DropDownList2.Items.Remove(i)
        Next
    End Sub

    Private Sub RemoveItems()
        Dim Li As ListItem
        For Each Li In DropDownList2.Items
            DropDownList2.Items.Remove(Li)
        Next
    End Sub

Thanks,
Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Figured it out:
    Private Sub RemoveItems()
        Dim i As Integer
        Dim b As ListItem

        For i = 0 To DropDownList2.Items.Count
            b = DropDownList2.SelectedItem
            DropDownList2.Items.Remove(b)
        Next

        Dim intValue As Integer = -1
        DropDownList2.Items.Insert(0, New UI.WebControls.ListItem("Please Select a Process System", intValue))

        DropDownList2.Enabled = False
    End Sub
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.