Search code examples
c#code-behindnested-repeater

Assign a Parent item with Child data in nested repeater C#


Can you set a parent tag (Label) with a child data within a nested repeater?

 <asp:Repeater ID="rpDB" runat="server" OnItemDataBound="rpDB_ItemDataBound" EnableViewState="true">
                <ItemTemplate>
                  <label class="glyphicon glyphicon-leaf" /><label id="rbt" runat="server"></label>
                  <asp:Repeater ID="rpDB_item" runat="server" OnItemDataBound="rpDB_item_ItemDataBound">
                                        <ItemTemplate>
                                            <div class="row anj">
                                                <div class="col-md-1 col-xs-1 glyphicon glyphicon-off" id="lblboot" runat="server" title=<%# DataBinder.Eval(Container.DataItem,"boot") %>></div> 
                                              </div>
                                        </ItemTemplate>
                 </asp:Repeater>    
                 </ItemTemplate>
</asp:Repeater>  

I would like to set label rbt in the parent repeater rpDB with the value of the lblboot in the child repeater rpDB_Item. Is this possible, and if so how. I see plenty pulling parent into child but not reversed.


Solution

  • Found the answer. I thought I had used this but must have been doing it wrong.
    (HtmlGenericControl) mycontrol = (HtmlGenericControl)(e.Item.Parent.Parent.FindControl("myControl"));

    This allowed me to set the attributes to a parent control.