Press Me
design the user control
asp:TextBox ID="tb" runat="server">then design the form
asp:PlaceHolder runat="server" ID="phCells">
asp:Button runat="server" ID="btnAdd" Text="Add" UseSubmitBehavior="false"
asp:HiddenField runat="server" ID="htnRowCount" Value="1"
start javascript code runat="server"
int cols = 1;
int numberOfRows = 0;
public int NumberOfRows
{
get { return int.Parse(this.Request.Form[this.htnRowCount.UniqueID] ?? "1"); }
set { this.htnRowCount.Value = value.ToString(); }
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Table table = new Table();
string target = this.Request.Form.Get("__EVENTTARGET");
if (string.IsNullOrEmpty(target))
numberOfRows=1;
else
{
if (target.Equals(this.btnAdd.UniqueID))
numberOfRows = this.NumberOfRows + 1;
}
for (int i = 0; i < numberOfRows; i++)
{
TableRow tr = new TableRow();
for (int j = 0; j < cols; j++)
{
TableCell td = new TableCell();
Control x = LoadControl("WebUserControl.ascx");
x.ID = "Cell" + i + j;
td.Controls.Add(x);
tr.Controls.Add(td);
}
table.Rows.Add(tr);
}
this.phCells.Controls.Add(table);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.NumberOfRows = numberOfRows;
}
No comments:
Post a Comment