Reputation: 1180
I have a checkboxlist for e.g. say 5 checkboxes having values 1,2,3,4 and 5 resp. I am selecting multiple checkboxes and I want to retrieve their values in the code behind. And then i want to concatenate their values with a ',' sign and store it in a string. For e.g.
If I select first,third and fifth checkbox then the final string should be 1,3,5
How can i achieve that?
Upvotes: 0
Views: 1509
Reputation: 460340
string values = string.Join(",", checkboxlist.Items.Cast<ListItem>()
.Where(i => i.Selected)
.Select(i => i.Value));
Upvotes: 2