Reputation: 927
In my page, there are check boxes multiple check boxes with values. I am taking this values from collection. I want to take the particular selected check box total count.
I tried the following code, But i am getting an error.
foreach (string key in collection.AllKeys)
{
var selectedCount = Convert.ToInt32(collection.GetValues(Convert.ToInt32(collection.AllKeys)).Contains("true"));
}
If i use the above code, the result is showing error like
Unable to cast object of type 'System.String[]' to type 'System.IConvertible'.
Give me some suggestions to find out?
Upvotes: 1
Views: 231
Reputation: 193
This should get the total and subtotal
int totalSelected = 0;
foreach (string key in collection.AllKeys)
{
int subTotalSelected = collection.GetValues(key).Where(x => x.Contains("true")).Count();
totalSelected += subTotalSelected;
}
Upvotes: 1