I have a CheckBoxList in my page.is there any way to get all selected item values using linq?
what is the best way to get selected item values in CheckBoxList?
You could go about this by taking the items of the checkbox list and converting them to ListItems and from that collection fetch those who is selected, like this:
var selectedItems = yourCheckboxList.Items.Cast<ListItem>().Where(x => x.Selected);
Here's an easy way
foreach (System.Web.UI.WebControls.ListItem oItem in rdioListRoles.Items)
{
if (oItem.Selected) // if you want only selected
{
variable = oItem.Value;
}
// otherwise get for all items
variable = oItem.Value;
}
List<string> selectedValues = chkBoxList1.Items.Cast<ListItem>().Where(li => li.Selected).Select(li => li.Value).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With