Hai Nguyen

Hai Nguyen

  • NA
  • 11
  • 0

assign text to a text box dynamically

Mar 3 2008 12:42 PM

Hello, I would like to assign text to a text box in a for next loop instead of the manual Textbox1.Text="Testing...";

I have a total of 10 text boxes and want to loop throught  all of these ten text boxes and assign text depening on the results of the SQL query from user..  I am not in a level that I can dynamically create and dispo text box on-the-fly yet in VS 2005 aspx web page yet :).  Right now I have an "if/ elseif" section to manually assign the text (textbox1.text="..";) depending how many items I get back from SQL results.  I would like to learn how to create and dispo text boxes on the fly later on...

I cannot find anything from Googling.. yet. I tried the "TextBox tb = new TextBox();" and tried to assign an ID to it (e.g. tb.ID= String.Format("Textbox{0}.Visible", var1);" but I guess that this is only in memory.  I found the property of all of my text boxes in  "Controls[0]Textbox1.text"  in the Controls but do not know to access it and assign text to it.

Appreciates tips and tricks from you.

Regards, HN


Answers (2)