hi
I have gridview with information of the itemNumber and the price I also checked the box of enable selection in gridView task when the user click on select the item number should be added to the listbox without adding the same number again how can I do it.. I know how to get the selected item number from gridview and adding it to the listbox but I don't know how to avoid adding duplicate items

here is my code

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewRow row = GridView1.SelectedRow;
        string id = row.Cells[0].Text;         
        ListBox1.Items.Add(id);



    }

Check if it's in the ListBox first

if (ListBox1.Items.Contains(id) == false) ListBox1.Items.Add(id);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.