VB.NET - Text Box Creation - Asked By Sreya Gopal on 13-Feb-12 02:17 AM

In my there is a text box for sealed containers,if the amount is less than or equal to 30,000 only one text box for sealed containers is needed,but f the amount is 60,000 two textboxes for sealed containers are needed.like that the no of textboxes generating depends on the amount.how can we do it, and we have to save the datas in the text boxes in the database ,that means during the creation of textboxes  fields in the database have to create dynamically.how can we do it both
dipa ahuja replied to Sreya Gopal on 13-Feb-12 02:36 AM
Try this :

 void getReuslt()
  {
    SqlDataAdapter da = new SqlDataAdapter("select * from tabl1""connString");
    DataTable dt = new DataTable();
    da.Fill(dt);
    foreach (DataRow row in dt.Rows)
    {
      TextBox txt = new TextBox();
      txt.Text = row["id"].ToString();
 
      TextBox txt2 = new TextBox();
      txt2.Text = row["name"].ToString();
 
 
      this.Controls.Add(txt);
      this.Controls.Add(txt2);
    }
  }
Web Star replied to Sreya Gopal on 13-Feb-12 03:39 AM
you can simply add textbox in vb.net form as follows

TextBox txtobj = new TextBox();
txtobj.Id = "txtName";
txtobj.Text = value;

this.Controls.Add(txtobj);

and you can put your condtion for number of textbox creation on the form using if or case what you want and put the business logic for that
hope this helps
kalpana aparnathi replied to Sreya Gopal on 13-Feb-12 04:18 AM
hi,

dim tx as new textbox()
me.controls.add(tx)
tx.name = "textbox1"
tx.text = "Hai I am dynamically created Text box"

Regards,