C# Code : -
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class jjjj : System.Web.UI.Page
{
int tl = 0;
private static int i = 0;
protected void Page_Load(object sender, EventArgs e)
{
}
public int NumberOfControls
{
get
{
if (ViewState["Count"] == null)
{
return 0;
}
return (int)ViewState["Count"];
}
set
{
ViewState["Count"] = value++;
}
}
private void ReadTextBoxes()
{
string strValue;
strValue = string.Empty;
int n = NumberOfControls;
for (int i = 1; i <= NumberOfControls; i++)
{
string boxName = "TextBoxID" + (i + 1).ToString();
Panel panl = Table1.FindControl(boxName) as Panel;
strValue += panl.ToString() + "\n";
//TextBox tb = Table1.FindControl(boxName) as TextBox;
//strValue += tb.Text + "\n";
}
Response.Write(strValue);
}
private void CreateTextBoxes()
{
for (int counter = 1; counter <= NumberOfControls; counter++)
{
Panel panl = new Panel();
panl.Width = 150;
panl.Height = 20;
panl.BorderWidth = 1;
Label lbpanel = new Label();
//TextBox tb = new TextBox();
//tb.Width = 150;
//tb.Height = 18;
//tb.TextMode = TextBoxMode.SingleLine;
if (counter == 1)
{
panl.ID = "TextBoxID" + (counter).ToString();
lbpanel.ID = "Label" + counter.ToString();
lbpanel.Text = ListBox1.SelectedValue.ToString();
Table table = new Table();
if (tl <= 30)
{
// Table Table1 = new Table();
table.ID = "tl" + tl.ToString();
for (int rows = 0; rows < 2; rows++)
{
TableRow tr = new TableRow();
int td = 0;
//for (int td = 0; td < 10; td++) ;
while (td <= 10)
{
TableCell tc = new TableCell();
TableCell tc1 = new TableCell();
TextBox tb = new TextBox();
tb.ID = "texb" + i.ToString();
tc.Controls.Add(tb);
tr.Cells.Add(tc);
i++;
td++;
}
//table2.Rows.Add(tr);
table.Rows.Add(tr);
panl.Controls.Add(table);
//table.Rows.Add(tr);
}
tl++;
}
}
else
{
panl.ID = "TextBoxID" + (counter + 1).ToString();
lbpanel.ID = "Label" + counter.ToString();
lbpanel.Text = ListBox1.SelectedValue.ToString();
Table table = new Table();
if (tl <= 30)
{
// Table Table1 = new Table();
table.ID = "tl" + tl.ToString();
for (int rows = 0; rows < 2; rows++)
{
TableRow tr = new TableRow();
int td = 0;
//for (int td = 0; td < 10; td++) ;
while (td <= 10)
{
TableCell tc = new TableCell();
TableCell tc1 = new TableCell();
TextBox tb = new TextBox();
tb.ID = "texb" + i.ToString();
tc.Controls.Add(tb);
tr.Cells.Add(tc);
i++;
td++;
}
//table2.Rows.Add(tr);
table.Rows.Add(tr);
panl.Controls.Add(lbpanel);
panl.Controls.Add(table);
//table.Rows.Add(tr);
}
tl++;
}
}
//tb.Text = "Enter Title " + counter;
TableRow FirstRow = new TableRow();
TableCell FirstCell = new TableCell();
//TextBox YourTextBox = new TextBox();
FirstCell.Controls.Add(panl);
FirstRow.Cells.Add(FirstCell);
Table1.Rows.Add(FirstRow);
}
}
protected override void CreateChildControls()
{
if (Page.IsPostBack)
{
NumberOfControls += 0;
CreateTextBoxes();
}
else
{
CreateTextBoxes();
NumberOfControls = 1;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (ListBox1.SelectedValue !=null)
{
NumberOfControls += 1;
}
else
{
}
}
}