2010-05-09 8 views
1

Bonjour les gars ici j'ai créé une table dynamique et comment puis-je définir les propriétés d de la table comme la hauteur, la largeur et etc? Pls me aider .. Merci ...Table dynamique dans Asp.Net

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

bonjour, docteur? mon chien, qui n'est pas là et que vous ne pouvez pas voir, est malade. Quel est le problème avec lui s'il vous plaît? - Voir le corollaire? affichez le code que vous avez et décrivez clairement le problème que vous rencontrez. –

+0

Merci pour votre commentaire. Et désolé ... privé void GenerateTable (int rowsCount) {Table table = new Table(); pour (int i = 0; i Sivakumar

+0

pas sur les commentaires votre code, éditez votre question, et placez-là – Aristos

Répondre

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

Cela ne fonctionne pas pour vous?