Dynamic table in Asp.Net
Hi guys here I've created d dynamic table and how can i set 开发者_如何学JAVAd 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;
}
// 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?
精彩评论