Best control to use to populate a N number of tablse with rows of data in dynamically

Kalpana 286 Reputation points


I have got a requirement where I have to generate a N number of tables based a list collection. In each of this tables, there would be a N number of rows.
The columns are fixed for the tables.
Which control is suitable for this purpose, I do not need any paging or sorting as the data would be sorted before it gets displayed.
I tried repeater control, but I am facing difficulty in creating the item template for it.
Are there any guidance that I can look up ?

Thank you.

A set of technologies in the .NET Framework for building web applications and XML web services.
3,362 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Lan Huang-MSFT 27,716 Reputation points Microsoft Vendor

    Hi @Kalpana ,
    I recommended that you use a repeater, it is used to display a repeated list of items.

    I tried repeater control, but I am facing difficulty in creating the item template for it.

    You said you encountered difficulties when using the repeater. Can you describe it in detail?
    Other controls of ASP.NET data binding Web server, such as Gridview, you can refer to the following article:
    I made a demo using a repeater, you can refer to it:
    The code:

    The Result:

    Best regards,
    Lan Huang

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Kalpana 286 Reputation points

    HI Lan Huang

    Yes, I am proceeding with a repeater control, the repeater control is created at the code behind, say if I have a collection of lists, for every list a method is run which creates the control and subsequently displays the data.
    Here is the code : -

      List<List<Bottleneckv11.SelectAllPU_Result>> groupedList = pulist.ToList()
                       .GroupBy(u => u.ProcessTypeName)
                       .Select(grp => grp.ToList())
                for(int i = 0; i < groupedList.Count; i++)
      internal void CreateDynamicRepeater(List<Bottleneckv11.SelectAllPU_Result> sublist)
                Repeater rpt = new Repeater();
                ITemplate header = LoadTemplate("rpthdr.ascx");
                rpt.HeaderTemplate = header;
                //rpt.HeaderTemplate = header;
                TemplateBuilder itemTemplate = new TemplateBuilder();
                for (int i = 0; i< sublist.Count; i++)
                    itemTemplate.AppendLiteralString("<td>" + sublist[i].ProcessUnitID + "</td>");
                    itemTemplate.AppendLiteralString("<td>" + sublist[i].ProcessUnitName + "</td>");
                    itemTemplate.AppendLiteralString("<td>" + sublist[i].JobOrderName + "</td>");
                    itemTemplate.AppendLiteralString("<td>" + i + "</td>");
                    itemTemplate.AppendLiteralString("<td>" + sublist[i].Result + "</td>");
                    itemTemplate.AppendLiteralString("<td>" + sublist[i].TotalAvailable + "</td>");
                rpt.ItemTemplate = itemTemplate;
                TemplateBuilder footer = new TemplateBuilder();
                footer.AppendLiteralString("<tr><td>End of Table</td></tr></table>");
                rpt.FooterTemplate = footer;
                rpt.DataSource = sublist;

    Right now, the data is displayed but it is repeated and this is how it looks now. I do not want the data to be repeated. It gets repeated based on the count of list. I think I am doing something wrong with the template builder. Please see if you could help.

  3. AgaveJoe 26,671 Reputation points

    Again, I would use a GridView.

     public partial class _default : System.Web.UI.Page  
            public class ViewModelRecord  
                public int Id { get; set; }  
                public string Name { get; set; }  
            protected void Page_Load(object sender, EventArgs e)  
            protected void PopulateGridViews()  
                List<List<ViewModelRecord>> tables = PopluateViewModelCollections();  
                int i = 0;  
                foreach(var table in tables)  
                    GridView gv = new GridView();  
                    gv.ID = $"table{i++}";  
                    gv.DataSource = table;  
            protected List<List<ViewModelRecord>> PopluateViewModelCollections()  
                List<List<ViewModelRecord>> tables = new List<List<ViewModelRecord>>();  
                for (int i = 0; i < 5; i++)  
                    List<ViewModelRecord> table = new List<ViewModelRecord>();  
                    for (int j = 0; j < 5; j++)  
                        table.Add(new ViewModelRecord() { Id = j, Name = $"item{i}-{j}" });      
                return tables;  


        <form id="form1" runat="server">  
                <asp:PlaceHolder ID="GridViewPlaceHolder" runat="server"></asp:PlaceHolder>  


    0 comments No comments