Your code makes not really sense for me:
- You are calling
item.FindControl("Label1")
in the inner loop. So you will get the same value multiple times when multiple check boxes are selected.
- You are setting the
Label5
within the outer loop multiple times.
As a result, you would have an empty list / string or one containing the same text multiple times. If that is intended, the code can be simplified to:
foreach (RepeaterItem item in Repeater1.Items)
{
CheckBoxList CheckBoxList1 = (CheckBoxList)item.FindControl("CheckBoxList1");
foreach (ListItem item1 in CheckBoxList1.Items)
{
if (item1.Selected == true)
{
Label lblname = (Label)item.FindControl("Label1");
Label5.Text = lblname.Text;
break;
}
}
}
If that is not intended, you should think about what you finally want to do and write appropriate code. I would at least expect that
Label5
should be set outside any loop.