How to dynamic adding rows into asp.net table ?

Posted by user359706 on Stack Overflow See other posts from Stack Overflow or by user359706
Published on 2010-06-09T07:45:12Z Indexed on 2010/06/09 8:02 UTC
Read the original article Hit count: 178

Filed under:
|

How can I add rows in a table from server-side?

  if (!Page.IsPostBack)
            {
                Session["table"] = TableId;
            }else
                TableId = (Table)Session["table"];
  }

protected void btnAddinRow_Click(object sender, EventArgs e)
        {
            num_row = (TableId.Rows).Count;

            TableRow r = new TableRow();
            TableCell c1 = new TableCell();
            TableCell c2 = new TableCell();
            TextBox t = new TextBox();

            t.ID = "textID" + num_row;
            t.EnableViewState = true;

            r.ID = "newRow" + num_row;
            c1.ID = "newC1" + num_row;
            c2.ID = "newC2" + num_row;

            c1.Text = "New Cell - " + num_row;
            c2.Controls.Add(t);

            r.Cells.Add(c1);
            r.Cells.Add(c2);

            TableId.Rows.Add(r);
            Session["table"] = TableId;

        }

in debug I found out the number in the "TableID", but the rows are not drawn.

Have you got an idea about this issue? Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET