Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

SOLVED

    protected void ButtonAddDevTools_Click(object sender, EventArgs e)
    {
        foreach (var vItem in ListBoxDevTools.Items)
        {
            if (ValueAlreadyInListDevTools(vItem))
                return;
        }


        ListBoxDevTools.Items.Add(
            new ListItem(
                DropDownListDevTools.SelectedItem.ToString() + " - " +
                RadioButtonListDevTools.SelectedItem.ToString(),
                DropDownListDevTools.SelectedValue));
    }

    private bool ValueAlreadyInListDevTools(object vItem)
    {
        var strCurrent = DropDownListDevTools.SelectedItem.ToString() + " - " +
                         RadioButtonListDevTools.SelectedItem.ToString();

        return strCurrent == vItem.ToString();
    }
share|improve this question
add comment

1 Answer

When I look at your code, I see that when the item is not in ListBoxDatabases, you add a new ListItem. This is not the same object as the DropDownListDB.SelectedItem (you create a new different object) So everytime you get there, you'll just add a new entry.

share|improve this answer
    
So is (ListBoxDatabases.Items.Contains(DropDownListDB.SelectedItem) == false) better? –  Kristian Salov Mar 13 '13 at 13:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.