Reputation: 5670
I have two nested repeater and a check box inside that, like this
<asp:Repeater ID="rptInterestCategory" runat="server" OnItemDataBound="rptInterestCategory_ItemDataBound">
<ItemTemplate>
<asp:Repeater ID="rptInterests" runat="server" OnItemDataBound="rptInterests_ItemDataBound">
<ItemTemplate>
<asp:CheckBox ID="cbInterest" runat="server" OnCheckedChanged="cbInterest_CheckedChanged" Data-Id='<%# DataBinder.Eval(Container.DataItem, "id") %>' Text='<%# DataBinder.Eval(Container.DataItem, "name") %>' />
</ItemTemplate>
</asp:Repeater>
<hr/>
</ItemTemplate>
</asp:Repeater>
Now on another button click event I want to find which all checkboxes(cbInterest
)are checked and need to get the value inside it. What will be the correct approach to do this?
Upvotes: 0
Views: 3451
Reputation: 11433
The way you would loop through them is to first get a reference to the nested Repeater:
Repeater rptInterests = (Repeater)rptInterestCategory.FindControl("rptInterests");
And then you can loop through the data items, find the checkbox, and get the value of the CheckBox:
foreach (RepeaterItem item in rptInterests.Items)
{
CheckBox cbInterest = (CheckBox)item.FindControl("cbInterest");
bool isChecked = cbInterest.Checked;
}
Upvotes: 3