Click here to Skip to main content
15,896,346 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have a dropdownlist ddlProduct Name and quantity text box. When I Select a Product Name and write the quantity in my textboxes and click the Button1 that number of textboxes are generating in my place holder according to quantity value. but when I am again go to choose the another product and quantity and click the Button 1 then the current quantity textboxes are generating and not showing the previous selected textboxes. I need to generate the textboes of present product and previous. Both should appear in my place holder.How will i Do it. Kindly Help.

C#
protected void Button1_Click(object sender, EventArgs e)
{
 
{
if (txtQuantity.Text != "")
{
for (int i = 0; i < Convert.ToInt16(txtQuantity.Text); i++)
{


Label la = new Label();
la.Text = ddlProductName.SelectedItem.Value + i.ToString();
la.ID = "abc" + i.ToString();
   
PlaceHolder1.Controls.Add(la);
 
//la = FindControl(String.Format(i)) as Label;
 

 

TextBox txtbox = new TextBox();
txtbox.Text = "Textbox - " + i.ToString();
 

PlaceHolder1.Controls.Add(new LiteralControl("<input id='txt' name='Textbox" + i + "'type='text' />"));
PlaceHolder1.Controls.Add(new LiteralControl("
"));
 
}
}
}

}
Posted
Updated 1-Apr-14 23:59pm
v3

1 solution

hope so you are missing to add the textbox control to PlaceHolder
 
TextBox txtbox = new TextBox();
txtbox.Text = "Textbox - " + i.ToString();
 
 
PlaceHolder1.Controls.Add(txtbox);

And see for more help
http://msdn.microsoft.com/en-us/library/kyt0fzt1(v=vs.110).aspx[^]
 
Share this answer
 
v2
Comments
Member 10578683 2-Apr-14 7:09am    
I have already written for adding text boxes
[no name] 2-Apr-14 7:11am    
You have not added txtbox to placeholder. plz check again ur code
Member 10578683 2-Apr-14 7:23am    
PlaceHolder1.Controls.Add(new LiteralControl("<input id='txt' name='Textbox" + i + "'type='text' />"));
PlaceHolder1.Controls.Add(new LiteralControl("
"));
This code generating Textboxes. My problem is how to see the prevous textboes before postback.
[no name] 2-Apr-14 8:04am    
I don't think so. Your generate texbox code is TextBox txtbox = new TextBox();
txtbox.Text = "Textbox - " + i.ToString();
and you have add this textbox name

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900