回 帖 发 新 帖 刷新版面

主题:当动态向添加Table中的行时,为什么我只能添加一行?添加第二行时第一行就消失了,这个怎么解决阿?

如题,当动态向添加Table中的行时,为什么我只能添加一行?添加第二行时第一行就消失了,这个怎么解决阿?谢谢!

回复列表 (共4个回复)

沙发

把你代码贴出来看看啊
用tbody然后添加listrow吧,这样比较好用

板凳

private void Button6_Click(object sender, System.EventArgs e)//增加行
    {
        TableRow hrow=new TableRow();

        TableCell hcell=new TableCell();
        hcell.Text=DropDownList7.SelectedValue;
        hrow.Cells.Add(hcell);

        hcell=new TableCell();
        hcell.Text=DropDownList8.SelectedValue;
        hrow.Cells.Add(hcell);

        hcell=new TableCell();
        hcell.Text=TextBox1.Text.Trim();
        hrow.Cells.Add(hcell);

        hcell=new TableCell();
        hcell.Text=DropDownList9.SelectedValue;
        hrow.Cells.Add(hcell);

        Table1.Rows.Add(hrow);
    }

3 楼

DataTable dt = new DataTable("t");
DataRow dr = dt.NewRow();
dt.Rows.Add(dr);


试试

4 楼

如果你不怕麻烦又怕出错的话,用最老实的办法:

private void Button6_Click(object sender, System.EventArgs e)//增加行
    {
        TableRow hrow=new TableRow();

        TableCell hcell=new TableCell();
        hcell.Text=DropDownList7.SelectedValue;
        hrow.Cells.Add(hcell);
        table1.rows.ass(hrow);

        hrow=new tablerow();
        hcell=new TableCell();
        hcell.Text=DropDownList8.SelectedValue;
        hrow.Cells.Add(hcell);
        table1.rows.add(hrow);

        hrow=new tablerow()
        hcell=new TableCell();
        hcell.Text=TextBox1.Text.Trim();
        hrow.Cells.Add(hcell);
        table.rows.add(hrow);

        hrow=new tablerow();
        hcell=new TableCell();
        hcell.Text=DropDownList9.SelectedValue;
        hrow.Cells.Add(hcell);
        Table1.Rows.Add(hrow);
    } 
可以试试看吧,虽然看起来有点麻烦但是有规律,不容易出错

我来回复

您尚未登录,请登录后再回复。点此登录或注册