Saturday, May 12, 2007

Getting All Selected Items of CheckListBox

Oh, after a while again I decided to start writing on this blog.

Any way, I thing sometimes it happens that you need to show some choices to your users then ask them to select any many as they want. So as you may know the best choice is CheckListBox. So after Binding it or adding your items into it you may want to get a list of SelectedItems over the checklistbox. So you have to iterate over your items then check whether if the item is checked or not like this:


foreach (ListItem item in CheckBoxList1.Items)
{
if(item.Selected)
{
Response.Write("<h3>" + item.Text + "</h3>");
}
}

Do not forget comments.

9 comments:

Anonymous said...

Thanks buddy !!!!!!!!!!!

Anonymous said...

it does not work....

ListItem is not an object ;(

fix your script ;)

Anonymous said...

Great job; just what I was looking for!

Franco said...

Works just great!!! Thanks!!!

Adeel Rizvi said...

its not working , i already try that before you and its a common logic to get the items but its not.

Mohammad said...

Great. Thanks a lot...

Anonymous said...

work fine man. thanks

Anonymous said...

thanks mate!!!!
really helps me :D

ashish sharma said...

thanks bro I really need this