You must use the Items property. In other words, your variable should begin with its value set to everything that should be before applying the selected elements. Then iterate over the elements, applying your logic to the variable, one element for each selected element. Then, no matter which user selects or deselects, you will always get the correct value for your variable.
int myValue = 0;
foreach(ListItem item in cbl.Items)
{
if(item.Selected) myValue += int.Parse(item.Value);
}
Jeff mattfield
source
share