SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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.