Hi ,
Check this
Well this example With Master page Scenario for this example in textbox enter how many of your controls you want to create then Click button1 Then Enter The values you want in Controls created Press Button2 it will retrieved the value you have Enterd before
protected void Page_Load(object sender, EventArgs e)
{
}
TextBox txtEngno;
TextBox txtChassis;
TextBox txtColour;
TextBox txtInvest;
TextBox txtFrieght;
TextBox txtYear;
Label lblEngno ;
Label lblChassis ;
Label lblColour ;
Label lblInvest ;
Label lblFrieght ;
Label lblYear;
TableRow row ;
TableRow row2;
TableCell cell11;
TableCell cell12 ;
TableCell cell13 ;
TableCell cell14;
TableCell cell15;
TableCell cell16;
TableCell cell21;
TableCell cell22;
TableCell cell23;
TableCell cell24;
TableCell cell25;
TableCell cell26;
TableRow row3;
Table tbl = new Table();
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 1; i <= int.Parse(txtQuantity.Text); i++)
{
txtEngno = new TextBox();
txtChassis = new TextBox();
txtColour = new TextBox();
txtInvest = new TextBox();
txtFrieght = new TextBox();
txtYear = new TextBox();
lblEngno = new Label();
lblChassis = new Label();
lblColour = new Label();
lblInvest = new Label();
lblFrieght = new Label();
lblYear = new Label();
row = new TableRow();
row2 = new TableRow();
cell11 = new TableCell();
cell12 = new TableCell();
cell13 = new TableCell();
cell14 = new TableCell();
cell15 = new TableCell();
cell16 = new TableCell();
cell21 = new TableCell();
cell22 = new TableCell();
cell23 = new TableCell();
cell24 = new TableCell();
cell25 = new TableCell();
cell26 = new TableCell();
row3 = new TableRow();
txtYear.ID = "txtYear-" + i;
txtEngno.ID = "txtEngno-" + i;
txtChassis.ID = "txtChassis-" + i;
txtColour.ID = "txtColour-" + i;
txtFrieght.ID = "txtFrieght-" + i;
txtInvest.ID = "txtInvest-" + i;
lblEngno.ID = "lblEngno-" + i;
lblChassis.ID = "lblChassis-" + i;
lblColour.ID = "lblColor-" + i;
lblYear.ID = "lblYear" + i;
lblInvest.ID = "lblInvest" + i;
lblFrieght.ID = "lblFrieght" + i;
lblEngno.Text = "Engine No. :";
lblYear.Text = "Year :";
lblInvest.Text = "Investment Price :";
lblFrieght.Text = "Frieght Price :";
lblChassis.Text = "Chassis No. :";
lblColour.Text = "Colour :";
cell11.Controls.Add(lblChassis);
cell12.Controls.Add(txtChassis);
cell13.Controls.Add(lblEngno);
cell14.Controls.Add(txtEngno);
cell15.Controls.Add(lblColour);
cell16.Controls.Add(txtColour);
cell21.Controls.Add(lblInvest);
cell22.Controls.Add(txtInvest);
cell23.Controls.Add(lblFrieght);
cell24.Controls.Add(txtFrieght);
cell25.Controls.Add(lblYear);
cell26.Controls.Add(txtYear);
row.Cells.Add(cell11);
row.Cells.Add(cell12);
row.Cells.Add(cell13);
row.Cells.Add(cell14);
row.Cells.Add(cell15);
row.Cells.Add(cell16);
row2.Cells.Add(cell21);
row2.Cells.Add(cell22);
row2.Cells.Add(cell23);
row2.Cells.Add(cell24);
row2.Cells.Add(cell25);
row2.Cells.Add(cell26);
row.BackColor = System.Drawing.Color.LightGray;
row2.BackColor = System.Drawing.Color.LightGray;
tbl.Rows.Add(row);
tbl.Rows.Add(row2);
row3.Cells.Add(new TableCell());
tbl.Rows.Add(row3);
}
ContentPlaceHolder cont = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
cont.Controls.Add(tbl);
Session["atbl"] = tbl;
ViewState.Add("countTimes", txtQuantity.Text);
}
protected void Button2_Click(object sender, EventArgs e)
{
tbl = new Table();
tbl = (Table)Session["atbl"];
ContentPlaceHolder cont = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
cont.Controls.Add(tbl);
string storeToDbValueOne = "";
foreach (TableRow tr in tbl.Rows)
{
foreach (TableCell cl in tr.Cells)
{
foreach (Control ctrl in cl.Controls)
{
if (ctrl is TextBox)
{
storeToDbValueOne += " , " + Request.Form[((TextBox)ctrl).UniqueID];
}
}
}
}
Response.Write("<script>alert('" + storeToDbValueOne + "')</script>");
}
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />
</asp:Content>
Best Regards
M.Mitwalli