문제

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?

도움이 되었습니까?

해결책

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;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top