<div> <table border="1" runat="server" id="tblInfo"> <tr> <td>Row 1</td> </tr> <tr> <td>Row 2</td> </tr> </table> <asp:Button runat="server" ID="btnAdd" OnClick="AddNewBtnClick" Text="Add Row"/> </div>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace OTED { public partial class WebForm1 : System.Web.UI.Page { public static int counter = 0; protected void Page_Load(object sender, EventArgs e) { rebuildMyTable(); } protected void rebuildMyTable() { if (this.ViewState["TableRowCount"] == null) this.ViewState["TableRowCount"] = 0; for (int i = 0; i < Int32.Parse(this.ViewState["TableRowCount"].ToString()); i++) AddNewRow(); } protected void AddNewBtnClick(object sender, EventArgs e) { AddNewRow(); if (this.ViewState["TableRowCount"] == null) this.ViewState["TableRowCount"] = 1; else { this.ViewState["TableRowCount"] = Int32.Parse((this.ViewState["TableRowCount"].ToString())) + 1; } } protected void AddNewRow() { HtmlTableCell cell = new HtmlTableCell(); HtmlTableRow row = new HtmlTableRow(); TextBox txt = new TextBox(); txt.ID = counter.ToString(); cell.Controls.Add(txt); row.Controls.Add(cell); int abc = tblInfo.Rows.Count; tblInfo.Controls.AddAt(abc, row); counter = counter + 1; } } }
int abc = tblInfo.Rows.Count; tblInfo.Controls.AddAt(abc, row);
tblInfo.Rows.Add(row);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)