0

I have an repeater inside another repeater. The second repeater have an checkbox event "isChecked_OnCheckedChanged". My problem is there. When this event occurs I need to access the value of the variable "lblName" and also the value of the variable "lblID" in parent repeater.

<asp:Repeater ID="rptOne" OnItemDataBound="populateSecondRepeater" runat="server">
    <HeaderTemplate>
        <table s>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td>
                <asp:Label ID="lblID" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
            </td>
            <td style="width: 15%; vertical-align: top;">
                <asp:Repeater ID="rptTwo" runat="server">
                    <HeaderTemplate>
                        <table>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <tr>
                            <td style="width: 85%;">
                                <img runat="server" src='<%# Eval("Img") %>' alt="#" id="img_flag" /></td>
                            <td style="width: 15%; padding-right: 40px">
                                <asp:Label ID="lblName" runat="server" Style="display: none;" Text='<%# Eval("IDName") %>'></asp:Label>
                                <asp:CheckBox ID="check" runat="server" AutoPostBack="True" Checked='<%# Eval("isChecked") %>' OnCheckedChanged="isChecked_OnCheckedChanged" />
                            </td>
                        </tr>
                    </ItemTemplate>
                    <FooterTemplate>
                        </table>
                    </FooterTemplate>
                </asp:Repeater>
            </td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

I can access the value of the variable "lblName", but how do I access the values ​​of the parent repeater?

protected void isChecked_OnCheckedChanged(object sender, EventArgs e)
{
        CheckBox chk = (sender as CheckBox);

        RepeaterItem item = chk.NamingContainer as RepeaterItem;
        if (item != null)
        {

            Label lbl = (Label) item.FindControl("lblName");
        }
}

thank you.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364

1 Answers1

0

There are multiple ways to do this. You can add something like ParentID property to your data model, set that to the value you want and bind that to a hidden field next to the lblName label.

Alternatively, use a <tr runat="server" id="rptOneRow"> for each item in rptOne, and jump up in isChecked_OnCheckedChanged from the RepeaterItem until you find such row. Then use FindControl to find the lblID.

Or see here how to access the data directly - Accessing parent data in nested repeater, in the HeaderTemplate.

Community
  • 1
  • 1
Pafka
  • 256
  • 2
  • 6