1

Hi guys here I've created d dynamic table and how can i set d properties of the table like height, width and etc? Pls help me.. Thanks...

code

private void GenerateTable(int rowsCount)
 {
   Table table = new Table(); 
   for (int i = 0; i < rowsCount; i++)
   {
     TableRow row = new TableRow();
     TableCell cell = new TableCell();
     TextBox tb1 = new TextBox();
     DropDownList drp1 = new DropDownList();
     tb1.ID= "dname"+i;drp1.ID = "relation" + i;      
     cell.Controls.Add(tb1);
     cell.Controls.Add(drp1);
     row.Cells.Add(cell);table.Rows.Add(row);
   }
   rowsCount++;
   ViewState["RowsCount"] = rowsCount;
 }
3
  • 1
    hello, doctor? my dog, whom is not here and you cannot see, is sick. what is wrong with him please? - see the corollary? post the code you have and clearly describe the problem you are having. Commented May 9, 2010 at 14:07
  • Thanks for ur comment.And sorry... private void GenerateTable(int rowsCount){Table table = new Table(); for (int i = 0; i < rowsCount; i++){TableRow row = new TableRow();TableCell cell = new TableCell();TextBox tb1 = new TextBox();DropDownList drp1 = new DropDownList();tb1.ID= "dname"+i;drp1.ID = "relation" + i;cell.Controls.Add(tb1);cell.Controls.Add(drp1);row.Cells.Add(cell);table.Rows.Add(row);}rowsCount++;ViewState["RowsCount"] = rowsCount;} This s my code... Commented May 9, 2010 at 14:38
  • not on comments your code, edit the your question, and place it there Commented May 9, 2010 at 15:03

1 Answer 1

2
// Create a new HtmlTable object.
    HtmlTable table1 = new HtmlTable();

    // Set the table's formatting-related properties.
    table1.Border = 1;
    table1.CellPadding = 3;
    table1.CellSpacing = 3;
    table1.BorderColor = "red";

    // Start adding content to the table.
    HtmlTableRow row;
    HtmlTableCell cell;
    for (int i = 1; i <= 5; i++)
    {
        // Create a new row and set its background color.
        row = new HtmlTableRow();
        row.BgColor = (i % 2 == 0 ? "lightyellow" : "lightcyan");

        for (int j = 1; j <= 4; j++)
        {
            // Create a cell and set its text.
            cell = new HtmlTableCell();
            cell.InnerHtml = "Row: " + i.ToString() +
              "<br>Cell: " + j.ToString();

            // Add the cell to the current row.
            row.Cells.Add(cell);
        }

        // Add the row to the table.
        table1.Rows.Add(row);
    }

    // Add the table to the page.
    this.Controls.Add(table1);

This doesn't work for you?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.