Question

At the moment I have to break down this simple operation in two parts, I am sure the would be a better way is hiding from me :

List<int> selectedValues= new List<int>();
...
IEnumerable<RadComboBoxItem> checkedItems = from checkedItem in cblMagistrateCourts.Items.ToList()
                                             where checkedItem.Checked == true
                                             select checkedItem;
foreach (RadComboBoxItem item in checkedItems)
{
     if (item.Checked)
          selectedValues.Add(Convert.ToInt32(item.Value));
}

I am wanting this to be done server-side only.

Was it helpful?

Solution

How about this?

List<int> selectedValues = cblMagistrateCourts.Items.Where(i => i.Checked)
                                                    .Select(i => Convert.ToInt32(i.Value))
                                                    .ToList();

OTHER TIPS

Convert the value at same time you're selecting the checkedItem...

List<int> selectedValues = (from checkedItem in cblMagistrateCourts.Items.ToList()
                            where checkedItem.Checked == true
                            select Convert.ToInt32(checkedItem.Value)).ToList();
rcb.CheckedItems.Select(x => x.Value).ToList();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top