sreenivasa reddy
sreenivasa reddy

Reputation: 11

How to retain listbox selected items values on multiple clicks?

for (int i = 0; i < lboxavilableInsName.Items.Count; i++)
{
    if (lboxavilableInsName.Items[i].Selected)
    {
        if (!arraylist1.Contains(lboxavilableInsName.Items[i]))
        {
            arraylist1.Add(lboxavilableInsName.Items[i]);
            arrUpdatedInsValues.Add(lboxavilableInsName.Items[i].Value);
            arrUpdatedInsNames.Add(lboxavilableInsName.Items[i].Text);                          
        }
        ViewState["UpdatedInsValues"] = arrUpdatedInsValues;
        arrUpdatedInsValuestotal = (ArrayList)ViewState["UpdatedInsValues"];
        ViewState["UpdatedInsValues2"] = `enter code here`arrUpdatedInsValuestotal;
        ViewState["UpdatedInsNames"] = arrUpdatedInsNames;
    }
}

Actually I have given selsectionmode="Multiple" in the listbox. That will select me multiple items when I select first time or subsequent time after page gets loaded, but I want that in a code behind saying ex: if I select 2 items 1st time that 2 items will added in the second listbox and I will get the values of those selected items.

If again I select any items after adding previous selection items in 2nd listbox, I want the item value selected at 2nd time along with first two item values. So totally 3 values I want. and I need to send that values to the stored procedure to insert.

Upvotes: 1

Views: 208

Answers (1)

M. Adeel Khalid
M. Adeel Khalid

Reputation: 1796

Its because you are assigning new values each time to the 2nd listbox, you don't need to assign them, you need to add values within your 2nd listbox, in this way your 2nd listbox will retain all the previous and the new values as well. Hope it helps.

Upvotes: 0

Related Questions