1

我用这些标题创建了一个表。现在如何使用 WHILE LOOP 并在页面加载时动态添加空行。就像我想要 40 个空行,每行 3 个单元格,我如何使用 while 循环并添加行?

ASP.NET C# Microsoft Visual Studio

    TableRow tr = new TableRow();

    TableCell tcel = new TableCell();
    tcel.Text = "id";
    tr.Cells.Add(tcel);

    TableCell tcel1 = new TableCell();
    tcel1.Text = "Work";
    tr.Cells.Add(tcel1);

    TableCell tcel2 = new TableCell();
    tcel2.Text = "Email";
    tr.Cells.Add(tcel2);

    Table1.Rows.Add(tr);
4

2 回答 2

1

很简单。附加这些:

var j = 0;
while (j++ < 40)
{
    var k = 0;
    var emptyRow = new TableRow();
    while (k++ < 3)
    {
        var emptyCell = new TableCell();
        emptyCell.Text = "|empty Cell|";
        emptyRow.Cells.Add(emptyCell);
    }
    Table1.Rows.Add(emptyRow);
}
于 2013-05-22T03:45:12.160 回答
0
int rowCount = 0;  
while(rowCount < 40)
{
    TableRow tr = new TableRow();
    int cellCount = 0;
    while(cellCount < 3)
    {
        TableCell tc = new TableCell();
        tc.Text = "cellText";
        tr.Cells.Add(tc);
        cellCount++;
    }
    Table1.Rows.Add(tr);
    rowCount++;
}
于 2013-05-22T04:27:52.693 回答