Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I have a text-box in grid view. when i write the quantity in text box then presses enter dynamically text-boxes will be generated according to the quantity inside the grid view placeholder.
Posted
Comments
So, what is the issue?
Member 10578683 22-Aug-14 3:31am    
I know how to dynamically generate the textboxes bt i dont know how on pressing enter key the textboes will generate.
public void fun1()
{
if (TextBox2.Text != "")
{


for (int i = 0; i <= Convert.ToInt16(TextBox2.Text) / 3; i++)
{


Label la = new Label();
la.Text = DropDownList2.SelectedItem.Value + (i + 1).ToString();
la.ID = "abc1" + i;

Panel3.Controls.Add(la);

//la = FindControl(String.Format(i)) as Label;




// TextBox Textbox = new TextBox();
// Textbox.ID = "txt" + i.ToString();


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


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

Panel3.Controls.Add(new LiteralControl("<br/>"));

}
for (int j = (Convert.ToInt16(TextBox2.Text) / 3) + 1; j <= Convert.ToInt16(TextBox2.Text) * 2 / 3; j++)
{


Label la1 = new Label();
la1.Text = DropDownList2.SelectedItem.Value + (j + 1).ToString();
la1.ID = "abc2" + j;

Panel4.Controls.Add(la1);
Panel4.Controls.Add(new LiteralControl("<input id='txt2' name='Textbox" + j + "'type='Text' />"));
Panel4.Controls.Add(new LiteralControl("<br/>"));





}
for (int k = (Convert.ToInt16(TextBox2.Text) * 2 / 3) + 1; k < Convert.ToInt16(TextBox2.Text); k++)
{


Label la2 = new Label();
la2.Text = DropDownList2.SelectedItem.Value + (k + 1).ToString();
la2.ID = "abc3" + k;

Panel5.Controls.Add(la2);

Panel5.Controls.Add(new LiteralControl("<input id='txt3' name='Textbox" + k + "'type='Text' />"));

Panel5.Controls.Add(new LiteralControl("<br/>"));

}
}



}
Ashi0891 22-Aug-14 3:48am    
can you use text box text changed event?
Member 10578683 22-Aug-14 4:08am    
no
See my answer. :)

1 solution

 
Share this answer
 
Comments
Ashi0891 22-Aug-14 3:55am    
good option!! +5 :)
Thanks Ashi0891. :)
Member 10578683 22-Aug-14 4:35am    
I wrote the code like this but it is not working protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i <= GridView1.Rows.Count; i++)
{
TextBox txt = (TextBox)GridView1.Rows[i].FindControl("TextBox2");
PlaceHolder ph = (PlaceHolder)GridView1.Rows[i].FindControl("PlaceHolder1");
for (int j = 0; j < Convert.ToInt32(txt.Text); j++)
{

ph.Controls.Add(new LiteralControl("<input id='txt' name='Textbox" + j + "'type='Text' />"));

ph.Controls.Add(new LiteralControl("<br/>"));

}

}
}
Member 10578683 22-Aug-14 4:43am    
It is working now.
thanks to all
Glad to hear that. :)

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