Click here to Skip to main content
15,898,990 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to create multiple dynamic tables. I've looked online about using repeaters and I've seen examples, but these examples cover always ONE table. I need to create MULTIPLE ones. For instance:

HTML
<table>
    <tr>
        <td colspan="4" style="width: 200px; font-weight: bold, font-size: xxx; etc etc">
              HTML blah blah blah
        </td>
    </tr>
    <tr>
        <td>HTML</td>
       <td>LABEL CONTROL - basicallly a label control rendering data</td>
       <td>HTML</td>
       <td>LABEL CONTROL - bascially a label control rendering data</td>
     </tr>
     <tr>
         <td colspan="2">
         </td>
         <td colspan="2">
         </td>
     </tr>
       .
       .
       .
</table>


Then, I would need to create a second table, maybe a third, or fourth, or tenth, etc. How do I go about this? The data would be coming from a Sharepoint List item. I will also need to add style to the table and TDs. No buttons or data within the table will be changed by the user... basically, the table will only display data.

Thanks in advance.

What I have tried:

I've read about repeaters being used, but repeaters I've read about only cover creating dynamic rows and tablecells, not tables themselves.
Posted
Updated 27-May-16 8:51am
v2
Comments
Peter Leow 27-May-16 0:24am    
You have read enough. It's time to get down to code. If you can create one dynamic table, what is stopping you from creating another one?

1 solution

You can create one table and use DataTable.Copy() or DataTable.Clone() method to create multiple tables, see below snippet

C#
DataTable dt = new DataTable();
dt.Columns.Add("Id");
dt.Columns.Add("Name");
dt.Columns.Add("Email");
dt.TableName = "MasterTable";

//insert into DataTable
dt.Rows.Add("1", "test1", "test1@gmail.com");
dt.Rows.Add("2", "test2", "test2@gmail.com");
dt.Rows.Add("3", "test3", "test3@gmail.com");

//Creating another DataTable to copy
DataTable dt_copy = new DataTable();
dt.TableName = "CopyTable";
dt_copy = dt.Copy();
 
Share this answer
 
Comments
TheAbominable 27-May-16 6:08am    
I think I figured it out. I am creating tables by using
Table table = new Table();
table.ID = "table" + currentTableNumber.ToString();
table.Style.Add("width", "800px");
etc.

So, my ordeal is, if I create two tables, HOW do I create space between the two tables? I tried creating a LABEL in the markup HTML and then assigning <br /><br /> to it, but that did not work. How do I go about doing this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900