【问题标题】:Dynamic creating table?动态创建表?
【发布时间】:2011-08-27 11:25:28
【问题描述】:

我正在编写用于在单击按钮时动态创建表的代码,我编写的代码工作正常,但是当我再次单击按钮时,我想将行添加到现有表中。请帮我。我的代码是:

Table table = new Table();
    table.ID = "Table1";
    Page.Form.Controls.Add(table);
    TableRow row = new TableRow();                       
    TableCell cell = new TableCell();
    TextBox tb = new TextBox();
    // Set a unique ID for each TextBox added
    tb.ID ="t1";
    tb.Text = "sasi";
    // Add the control to the TableCell
    cell.Controls.Add(tb);
    // Add the TableCell to the TableRow
    row.Cells.Add(cell);
    table.Rows.Add(row);

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    单击按钮后,您将需要代码

    Table table = (Table) Page.Form.FindControl("Table1");
    

    但是,您需要确保在回发页面时重新构建表格,否则FindControl 将找不到任何内容,table 将为空。

    【讨论】:

      猜你喜欢
      • 2012-05-03
      • 2018-08-12
      • 2017-02-25
      • 2016-08-20
      • 2016-10-14
      • 2017-01-31
      • 2011-12-03
      • 1970-01-01
      相关资源
      最近更新 更多