2010-05-09 21 views
1

嗨,大家好我在這裏創建了d動態表,我如何設置表的高d,寬度等d屬性?請幫助我..謝謝...Asp.Net中的動態表

代碼

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; 
} 
+1

你好,醫生?我的狗,不在這裏,你看不到,是病。他有什麼不好嗎? - 看到推論?發佈您的代碼並清楚地描述您遇到的問題。 – 2010-05-09 14:07:48

+0

感謝您的評論。並對不起... private void GenerateTable(int rowsCount){Table table = new Table();對於(int i = 0; i Sivakumar 2010-05-09 14:38:54

+0

不在評論你的代碼,編輯你的問題,並將其放置在那裏 – Aristos 2010-05-09 15:03:20

回答

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); 

這並不爲你工作?