priyanka bhatnagar

priyanka bhatnagar

  • NA
  • 48
  • 10.3k

How to add integer to textbox name in for loop

Mar 19 2015 7:42 AM
for(int k=1;k<=f;k++)
{
textbox+k+.text=file[k]

}
here it is not correct way to concatenate textbox and integer

Answers (4)

0
Vulpes

Vulpes

  • 0
  • 96k
  • 2.6m
Mar 19 2015 8:25 AM
If the textboxes are named textbox1, textbox2 etc. and  have all been placed directly on the form (and not in some container such as a panel or groupbox), then try this:

for(int k = 1; k <= f; k++)
{
   ((TextBox)this.Controls["textbox" + k]).Text = file[k];
}

Accepted Answer
1
Jignesh Trivedi

Jignesh Trivedi

  • 0
  • 62.3k
  • 46m
Mar 19 2015 9:47 AM

hi,

Control collection contain all control of page using following code you may find all text box on page.

foreach (var c in this.Controls.OfType<TextBox>())
{
    c.Text = c.Name;
}

hope this will help you.

0
Khargesh Rajput

Khargesh Rajput

  • 319
  • 5.6k
  • 606.6k
Mar 19 2015 8:17 AM
textbox+k+".Text"=file[k]
0
Keertti Raj  Thangavelu Babu

Keertti Raj Thangavelu Babu

  • 0
  • 516
  • 36.1k
Mar 19 2015 8:06 AM
Hi priyanka,
     
May I Know in details.Are you assign a value to already created textboxs or dynamic textboxs