Dynamic table

C Sharp - C# (programming language)
Post Reply
dzcadii
Posts: 94
Joined: Sun Mar 01, 2015 4:36 am

Dynamic table

Post by dzcadii » Sun Mar 01, 2015 10:47 pm

Code: Select all

<%    
    // create a string type variable to generate dynamic table  
    string dynTable = "";

    // start with table tag with following attributes   
    dynTable = "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";

    // outer loop to generate table rows  
    for (int tRows = 0; tRows < 10; tRows++)
    {
        //start table row  
        dynTable += "<tr>";

        // inner loop to generate columns  
        for (int tCols = 0; tCols < 2; tCols++)
        {
            // create column  
            dynTable += "<td>";
            dynTable += "Row: " + (tRows + 1) + " Col: " + (tCols + 1);

            // close td column tag  
            dynTable += "</td>";
        }

        // close table row  
        dynTable += "</tr>";
    }

    // close the table tag  
    dynTable += "</table>";
    
 %>
<%= dynTable %>
Reference:
ASP.Net C# Code to Create Dynamic Tables

Post Reply