Im using LINQ to retrive cheched Items from CheckBoxList control:
Here the LINQ :
IEnumerable<int> allChecked = (from ListItem item in CheckBoxList1.Items
where item.Selected
select int.Parse(item.Value));
My question is why item have to be ListItem type?
The CheckedListBox was created before generics were introduced, thus the Items collection returns objects rather than the strongly typed ListItem. Luckily, fixing this with LINQ is relatively easy using the OfType() (or Cast) methods: