开发者

Dynamic creating table?

I am writing a code for dynamically creating table in a button click, i Write the code it is working fine, But when i click the button again i want to add the rows to the existing table. Please help me. My code is :

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 开发者_如何学Pythonfor 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);


On your button click, you will want to have the code

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

However, you will need to make sure that you are re-building the table on postback of the page, otherwise the FindControl will not find anything, and table will be null.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜