rowmark
asked on
ListBox item removal issue
Hello Experts,
I have two Listboxes in my ASPX page. On page load the first listbox(lballcolumns) lists all the items from the db after loading all items using the below code I am removing the items that all already in the second Listbox(lbselected).
for (int i = lbselectedColumns.Items.Co unt-1; i >= 0; i--)
{
if (lbselectedColumns.Items[i ].Selected )
{
lballcolumns.Items.RemoveA t(i);
}
}
But somehow last item is not getting removed. For eg. if First Name is the last column in my dbtable, that is not getting removed. What may be the reason.
Please help
I have two Listboxes in my ASPX page. On page load the first listbox(lballcolumns) lists all the items from the db after loading all items using the below code I am removing the items that all already in the second Listbox(lbselected).
for (int i = lbselectedColumns.Items.Co
{
if (lbselectedColumns.Items[i
{
lballcolumns.Items.RemoveA
}
}
But somehow last item is not getting removed. For eg. if First Name is the last column in my dbtable, that is not getting removed. What may be the reason.
Please help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The problem could be that as you remove the items the value of lbselectedColumns.Items.Co unt is decreasing so you could infact just jump over items. Try doing a i-- inside the if clause.