Nested Web Controls

Hi!
To create a special report, I have to use nested Repeaters as below:

<asp:Repeater ID="rpt1" Runat="server">
 <ItemTemplate>

  <asp:Repeater ID="rpt2" Runat="server">
   <ItemTemplate>
   </ItemTemplate>
  </asp:Repeater>

  .
  .
  .

 </ItemTemplate>
</asp:Repeater>

But I may not call the inner Repeater through my code. Therefore it is impossible to set the Data Source and the other properties of rpt2. Please help me.

Regards!
M.Sadegh Samiei



Answer this question

Nested Web Controls

  • Eye5600

    True... you cannot access it normally. However, you can do this:

    Create an evenhandler for the ItemDataBound event and place the following code:


     protected void rp1_ItemDataBound(object sender, RepeaterItemEventArgs e)
     {
      Repeater rp = (Repeater)e.Item.FindControl("rp2");
      if (rp != null)
      {
       rp.DataSource = table2;
       rp.DataBind();
      }

     }


     


    That should do the trick!


  • Nested Web Controls