Dean
Dean

Reputation: 372

ASP.Net remove item from drop down list?

I have a drop down list which is filled via a DataGrid. In certain cases I would like to remove some items from this list. The variable "SoftwareToRemoveFromList" will be filled with the item I want to remove.

So far I have this code:

    Dim removeListItem As ListItem = SoftwareDropDown.Items.FindByText(SoftwareToRemoveFromList)
        SoftwareDropDown.Items.Remove(removeListItem)

This runs without error and the contents of "removeListItem" has the string that I want to remove from the drop down. However, when it runs it doesn't actually remove anything from the drop down? Just wondering what I'm missing here?

Upvotes: 0

Views: 242

Answers (1)

Júlio Murta
Júlio Murta

Reputation: 545

Removing by index works for me

    Dim removeListItem As Integer = SoftwareDropDown.Items.IndexOf(SoftwareDropDown.Items.FindByText(SoftwareToRemoveFromList))
    SoftwareDropDown.Items.RemoveAt(removeListItem)

Upvotes: 1

Related Questions