I want to speed ChechBoxList's getting the selected items, the normal approach is

foreach (ListItem li in checkListBox.Items)
{
if (li.Selected)
{
}
}

but if I've 6000 items in the CheckListBox, that's mean I should go through the 6000 items to know which is selected. Performance POOOOOOR!!!
Is there way to get just selected ItemsCollection ??

Recommended Answers

All 3 Replies

That was abount the most stupid post I have sent

I think I will edit it out
wish there was a delete button

I dont think there is a built in method to get selected ItemsCollection only. Even if there is one, the algorithm would be the same as yours. So it wont solve the performance issue. One way to do this will be to use a javascript function to append the indices of only the selectedItem to a hiddenfield on its onClientClick event and then to parse the hidden field value in your code behind to get the Selected item indices.
If you get another good reliable way of doing it please post it here so that everyone can learn
Thanks

commented: Nice help :) +6

I got this solution too but for some reasons I preferred server side, yes Java Script would be better, Thank you Aneesh_Argent so much :)

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.