est-il possible de créer dynamiquement des colonnes de table html (< th> </th>) en utilisant namespae System.Web.UI.HtmlControls?ASP.NET Création dynamique HTMLTableColumns (en-têtes)
2
A
Répondre
3
essayez ceci:
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);
2
Oui dans cet espace de nom que vous voulez regarder:
HtmlTable
HtmlTableRow
HtmlTableCell
utilisation est comme ceci:
HtmlTable htmlTable = new HtmlTable(); //creating table object
HtmlTableRow htmlRow = new HtmlTableRow(); //creating row object
HtmlTableCell htmlTableCell = new HtmlTableCell(); //create cell
htmlTableCell.InnerHtml = "<b>Test Text Bolded</b>";//setting cell content
HtmlTableCell textTableCell = new HtmlTableCell(); //create cell
textTableCell.InnerText = "Test plain text"; //setting cell content
htmlRow.Cells.Add(htmlTableCell); //add cell to row
htmlRow.Cells.Add(textTableCell); //add cell to row
htmlTable.Rows.Add(htmlRow); // add row to table
1
HtmlTableCell = new HtmlTableCell("th");
Questions connexes
- 1. ASP.NET Dynamique Création d'un contrôle personnalisé
- 2. création contrôle dynamique
- 3. gtm-http-fetcher modifier entêtes HTTP
- 4. création dynamique avec textboxes « échange »
- 5. contrôles personnalisés, la création dynamique
- 6. Création dynamique des modèles - entités utilisant Asp.Net MVC
- 7. Problème Création Id dynamique pour textbox dans asp.net mvc
- 8. Création dynamique de contrôle
- 9. création html dynamique C#
- 10. Création dynamique de XSD
- 11. Création dynamique de typedef
- 12. Création de type dynamique
- 13. Création d'une expression régulière dynamique
- 14. Création dynamique d'attributs de classe
- 15. Création d'un dataset dynamique XtraPivotGrid
- 16. objectif c création d'objet dynamique
- 17. Création d'un flux iCalendar dynamique
- 18. Création d'un fichier XML dynamique
- 19. Expression.OrElse, création dynamique d'une condition
- 20. Création dynamique zip avec php
- 21. Création dynamique de tablelayout android
- 22. Création d'un bouton radio dynamique
- 23. Création d'une dynamique de déclenchement
- 24. Création chaîne de requête dynamique
- 25. Création dynamique de classes - Python
- 26. Création d'un menu horizontal dynamique
- 27. graphviz: création dynamique du noeud
- 28. création d'intervalle dynamique dans SQL
- 29. création XML dynamique avec php
- 30. Création d'une requête LINQ dynamique