By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,017 Members | 1,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,017 IT Pros & Developers. It's quick & easy.

problem with getting value of dynamically created textbox

coolv
P: 6
Hello everyone,

I m generating dynamic textbox depending on the value selected from the dropdownlist(DropDownList1_SelectedIndexChanged).e g: if i select 3 from dropdownlist,then 3 textbox is generated.

But the problem is that when i click on insert button(btnadd_Click) ,then i don't get the value those are inserted into generated textboxes.

Below is my code:


Expand|Select|Wrap|Line Numbers
  1.     protected void  btnadd_Click(object sender, EventArgs e)
  2.     {
  3.         for(int i=0; i<Convert.ToInt32(DropDownList1.SelectedValue); i++)
  4.         {
  5.  
  6.          TextBox textBox =(TextBox)Panel1.FindControl("myTextBox" + i.ToString());
  7.         if (textBox != null)
  8.         {
  9.  
  10.           touchpay.exce("Insert into card_pin_master(company_id,card_type,pin,card_id) values('" + dpwcompany.SelectedValue + "','" + dpwtype.SelectedValue + "','" + textBox.Text+ "',"+dpwcardname.SelectedValue+"')");
  11.         }
  12.         }
  13.     }
  14.     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  15.     {
  16.         for (int x = 0; x < Convert.ToInt32(DropDownList1.SelectedValue); x++)
  17.         {
  18.             TextBox textarray = new TextBox();
  19.             textarray.ID = "myTextBox" + x.ToString();
  20.             //textarray.Visible = false;
  21.            Panel1.Controls.Add(textarray);
  22.         }
  23.     }
Jan 11 '08 #1
Share this Question
Share on Google+
1 Reply


Frinavale
Expert Mod 5K+
P: 9,731
I've started an article on using dynamic controls in .NET. It's not complete but it covers how to dynamically load textboxes and retrieve their values. It's not complete and it's in VB.NET, but the example works and is easily translated into C#.

My guess is that you are not properly initializing your text boxes in your Page_Init method (you haven't posted this method).

Check out the rough article and then get back to me if you're still having problems.

-Frinny
Jan 11 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.