Results 1 to 3 of 3

Thread: Creating html table dynamically

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    58

    Question Creating html table dynamically

    I have a for loop (dataset returns 10 records) . I need to keep creating html tables till a certain condition meet. e.g: if loop count is 10 then 10 html tables will be generated with 3 rows and 4 cols displaying text values from my dataset. can anyone help me how to create html tables dynamically using for loop, and how to add multiple cols and rows in one table and then add text in rows and cols from my dataset.

    thanks

  2. #2
    New Member
    Join Date
    Sep 2007
    Posts
    4

    Re: Creating html table dynamically

    this might help

    for (int k = 0; k < 4; k++)
    {
    HtmlTable table1 = new HtmlTable();
    table1.ID = "table1" + k;
    for (int i = 1; i < 4; i++)
    {
    HtmlTableRow row = new HtmlTableRow();
    row.ID = "row" + i;

    for (int j = 1; j < 4; j++)
    {
    HtmlTableCell cell = new HtmlTableCell();
    cell.ID = "cell" + j;
    cell.InnerHtml = "cell" + i + j;
    row.Cells.Add(cell);
    }
    table1.Rows.Add(row);
    }
    table1.CellPadding = 2;
    table1.CellSpacing = 2;
    table1.BorderColor = "Green";
    table1.Border = 2;
    }

  3. #3
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Re: Creating html table dynamically

    Please us the editor to format your code in more readable segments using a formatting tag.

    Examples:


    [code]
    for (int j = 1; j < 4; j++)
    {
    HtmlTableCell cell = new HtmlTableCell();
    cell.ID = "cell" + j;
    cell.InnerHtml = "cell" + i + j;
    row.Cells.Add(cell);
    }
    [/code]






    [php]
    for (int j = 1; j < 4; j++)
    {
    HtmlTableCell cell = new HtmlTableCell();
    cell.ID = "cell" + j;
    cell.InnerHtml = "cell" + i + j;
    row.Cells.Add(cell);
    }
    [/php]





    [HIGHLIGHT="VB.NET"]
    for (int j = 1; j < 4; j++)
    {
    HtmlTableCell cell = new HtmlTableCell();
    cell.ID = "cell" + j;
    cell.InnerHtml = "cell" + i + j;
    row.Cells.Add(cell);
    }
    [/HIGHLIGHT]



    Which Formats your text like so:



    Code:
    for (int j = 1; j < 4; j++)
    {
        HtmlTableCell cell = new HtmlTableCell();
        cell.ID = "cell" + j;
        cell.InnerHtml = "cell" + i + j;
        row.Cells.Add(cell);
    }
    PHP Code:
    for (int j 14j++)
    {
        
    HtmlTableCell cell = new HtmlTableCell();
        
    cell.ID "cell" j;
        
    cell.InnerHtml "cell" j;
        
    row.Cells.Add(cell);

    VB.NET Code:
    1. for (int j = 1; j < 4; j++)
    2. {
    3.     HtmlTableCell cell = new HtmlTableCell();
    4.     cell.ID = "cell" + j;
    5.     cell.InnerHtml = "cell" + i + j;
    6.     row.Cells.Add(cell);
    7. }
    Last edited by wey97; Sep 27th, 2007 at 04:08 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width