表控件中的动态添加表行 [英] Dynamic add table row in table control

查看:80
本文介绍了表控件中的动态添加表行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个表,并且希望在该表中动态添加行.

I have created a table and I want to add row dynamically in this table.

<asp:Table ID="Table1" runat="server" Width="36px">
<asp:Table>



代码文件:



Code file:

protected void Button1_Click(object sender, EventArgs e)
    {
        TableRow row = new TableRow();
        TableCell cell1 = new TableCell();
        TableCell cell2 = new TableCell();
        TextBox txtt = new TextBox();
       
        txtt.ID = "txt";

        DropDownList dpn_phone = new DropDownList();
        dpn_phone.Items.Add("Home");
        dpn_phone.Items.Add("Work");
        dpn_phone.Items.Add("Mobile");
        dpn_phone.ID = "pho";

        cell1.Controls.Add(txtt);
        cell2.Controls.Add(dpn_phone);
        row.Cells.Add(cell1);
        row.Cells.Add(cell2);

        Table1.Rows.Add(row);
        ph.Controls.Add(t);
    }



但是,当发生任何往返行程时,Table1行将被删除



But when any round trip is happening then Table1 rows are deleting

推荐答案

您是否在回发之前将新行保留在ViewState中,以便可以将以前创建的任何行加回表中了吗?

[
Have you preserved the new rows in ViewState prior to a post back so that any previously created rows can be added back to the table?

This[^] might help to get you started.


这篇关于表控件中的动态添加表行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆