Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 180483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:35:40+00:00 2026-05-11T14:35:40+00:00

I am trying to create nested repeaters dynamically using ITemplate. This repeater is like

  • 0

I am trying to create nested repeaters dynamically using ITemplate. This repeater is like that I am passing List<Control> and it generates repeater. Issue is that when I databound outer repeater. Only the last nested repeater shows. Following is screen shot. screen shot

Markup


    <%@ Page Language='C#' AutoEventWireup='true' CodeFile='Default.aspx.cs' Inherits='Restricted_Default' %>  <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>  <html xmlns='http://www.w3.org/1999/xhtml'> <head runat='server'>     <title></title> </head> <body>     <form id='form1' runat='server'>     <div>     <table style='border:solid 1px black;'>         <tr>             <td>                 <asp:PlaceHolder ID='phControls' runat='server' />             </td>         </tr>     </table>     </div>     </form> </body> </html> 

Code Behind


 using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data;  public partial class Restricted_Default : System.Web.UI.Page {     protected void Page_Load(object sender, EventArgs e)     {         CreateNestedRepeater();     }      private void CreateNestedRepeater()     {         Repeater childRpt = new Repeater();         List repeatingRuleControls = new List();         repeatingRuleControls.Add(new TextBox());         repeatingRuleControls.Add(new TextBox());         repeatingRuleControls.Add(new TextBox());         RepeatingRuleTemplate repeatingRuleTemplate = new RepeatingRuleTemplate(ListItemType.Item, repeatingRuleControls);         childRpt.HeaderTemplate = new RepeatingRuleTemplate(ListItemType.Header, repeatingRuleControls);         childRpt.ItemTemplate = repeatingRuleTemplate;         childRpt.FooterTemplate = new RepeatingRuleTemplate(ListItemType.Footer, null);         childRpt.DataSource = new DataRow[4];          Repeater parentRpt = new Repeater();         repeatingRuleControls = new List();         repeatingRuleControls.Add(new TextBox());         repeatingRuleControls.Add(new TextBox());         repeatingRuleControls.Add(new TextBox());         repeatingRuleControls.Add(childRpt);         RepeatingRuleTemplate parentrepeatingRuleTemplate = new RepeatingRuleTemplate(ListItemType.Item, repeatingRuleControls);         parentRpt.HeaderTemplate = new RepeatingRuleTemplate(ListItemType.Header, repeatingRuleControls);         parentRpt.ItemTemplate = parentrepeatingRuleTemplate;         parentRpt.FooterTemplate = new RepeatingRuleTemplate(ListItemType.Footer, null);         parentRpt.DataSource = new DataRow[4];         parentRpt.DataBind();         phControls.Controls.Add(parentRpt);     }      public class RepeatingRuleTemplate : ITemplate     {         ListItemType templateType;         List innerControls;          public RepeatingRuleTemplate(ListItemType type, List controls)         {             templateType = type;             innerControls = controls;         }            public void InstantiateIn(Control container)         {             PlaceHolder ph = new PlaceHolder();              switch (templateType)             {                 case ListItemType.Header:                     ph.Controls.Add(new LiteralControl(''));                     ph.Controls.Add(new LiteralControl(''));                     foreach (Control control in innerControls)                     {                         Label label = new Label();                         label.Text = control.ID;                         ph.Controls.Add(new LiteralControl(''));                         ph.Controls.Add(label);                         ph.Controls.Add(new LiteralControl(''));                     }                     ph.Controls.Add(new LiteralControl(''));                     break;                 case ListItemType.Item:                     ph.Controls.Add(new LiteralControl(''));                      foreach (Control control in innerControls)                     {                         if (control.GetType() != typeof(Repeater))                         {                             ph.Controls.Add(new LiteralControl(''));                             TextBox textBox = new TextBox();                             textBox.ID = control.ID;                             ph.Controls.Add(textBox);                             ph.Controls.Add(new LiteralControl(''));                         }                         else                         {                             ph.Controls.Add(new LiteralControl(''));                             ph.Controls.Add(control as Repeater);                             //(control as Repeater).DataSource = new DataRow[4];                             //   (control as Repeater).DataBind();                             ph.Controls.Add(new LiteralControl(''));                         }                     }                     ph.Controls.Add(new LiteralControl(''));                     //ph.DataBinding += new EventHandler(Item_DataBinding);                     break;                 case ListItemType.Footer:                     ph.Controls.Add(new LiteralControl(''));                     break;             }             container.Controls.Add(ph);         }            public List Controls         {             get             {                 return innerControls;             }         }      } } 

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:35:41+00:00Added an answer on May 11, 2026 at 2:35 pm

    Ok guys I figured it out …. Thanks to everyone though. I was doing a mistake. The template class was wrong.I fixed it and now it is working like Charm Follwoing is the class

      public class RepeatingRuleTemplate : ITemplate     {         ListItemType templateType;         List innerControls;

    public RepeatingRuleTemplate(ListItemType type, List<Control> controls) { templateType = type; innerControls = controls; } public void InstantiateIn(Control container) { PlaceHolder ph = new PlaceHolder(); switch (templateType) { case ListItemType.Header: ph.Controls.Add(new LiteralControl('<table border=\'0\'>')); ph.Controls.Add(new LiteralControl('<tr>')); foreach (Control control in innerControls) { Label label = new Label(); label.Text = control.ID; ph.Controls.Add(new LiteralControl('<td>')); ph.Controls.Add(label); ph.Controls.Add(new LiteralControl('</td>')); } ph.Controls.Add(new LiteralControl('</tr>')); break; case ListItemType.Item: ph.Controls.Add(new LiteralControl('<tr>')); foreach (Control control in innerControls) { //ph.Controls.Add(new LiteralControl('<td>')); //ph.Controls.Add(control as TextBox); //ph.Controls.Add(new LiteralControl('</td>')); if (control.GetType() != typeof(Repeater)) { ph.Controls.Add(new LiteralControl('<td>')); TextBox textBox = new TextBox(); textBox.ID = control.ID; ph.Controls.Add(textBox); ph.Controls.Add(new LiteralControl('</td>')); } else { ph.Controls.Add(new LiteralControl('<td>')); Repeater rpt = new Repeater(); rpt.DataSource = (control as Repeater).DataSource; rpt.ItemTemplate = (control as Repeater).ItemTemplate; rpt.HeaderTemplate = (control as Repeater).HeaderTemplate; rpt.FooterTemplate = (control as Repeater).FooterTemplate; rpt.DataBind(); ph.Controls.Add(rpt); //(control as Repeater).DataSource = new DataRow[4]; // (control as Repeater).DataBind(); ph.Controls.Add(new LiteralControl('</td>')); } } ph.Controls.Add(new LiteralControl('</tr>')); //ph.DataBinding += new EventHandler(Item_DataBinding); break; case ListItemType.Footer: ph.Controls.Add(new LiteralControl('</table>')); break; } container.Controls.Add(ph); } public List<Control> Controls { get { return innerControls; } } }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 217k
  • Answers 218k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You've mapped the ProjectNotes table twice. Once into the Project.Notes… May 12, 2026 at 11:28 pm
  • Editorial Team
    Editorial Team added an answer HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\YourProgramName\DisplayIcon DisplayIcon should be a REG_SZ key and should give… May 12, 2026 at 11:28 pm
  • Editorial Team
    Editorial Team added an answer Short answer: svn does not operate that way. Less-short-but-not-long answer:… May 12, 2026 at 11:28 pm

Related Questions

As Anton points out (thanks Anton!) my problem is Association Caching in the tests
I am trying to create an ActiveRecord object via a JSON request. However the
I am attempting to create a report that contains a list nested within another
I'm trying to set the DisplayMember Property of my ListBox in a windows forms

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.