I have a dynamically created CheckBoxList. Within this CheckBoxList, I have a nested foreach loop used to validate a user input. The user enters his or her email address. Once the user clicks submit, the CheckBoxList is created. If the user's email matches a subscription to a topic, the checkbox next to that topic is selected. The problem I'm having is relating the original outer foreach to the nested foreach.
int i = 0;
foreach (Topic topic in result)
{
string topicName = topic.TopicArn.ToString().Split(':').Last();
ListItem li = new ListItem(topicName, topic.TopicArn);
checkBoxList1.Items.Add(li);
foreach (Subscription subscription in subs) // where topic equals current
// topic in original foreach?
{
if (txtEmail.Text == subscription.Endpoint)
checkBoxList1.Items[i].Selected = true;
}
i++;
}
I was thinking I might be able to use LINQ to add a condition to the nested foreach loop, but I haven't been able to pull it all together yet.