Skip to content

Dynamic control names - fill controls in loop

jo

Asked Jun 28, 2009, 10:48 PM EDT1 answer
Share
LinkedInX
Hi,
i have a form with controls that show productinformation.
now i have 10 textboxes named tbxPrice1 -> tbxPrice10 .
in my artikecleobject exists a property list<articleprice> named articlepricelist that could have 0 till 10 elements.
now i want to fill my 10 textboxes in a loop against my articlepricelist property.
If the articlepricelist contains 3 elements, the first 3 textboxes tbxPrice1,tbxPrice2 and tbxPrice3 should be filled.
If the articlepricelist is empty, no textbox should be filled.
Has anybody an idea, how to do this ?
by jo

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    string[] arr = new string[10];
    for (i = 0; i < count; i++)
    {
    Control[] ctrls = Form1.Controls.Find("Textbox1", false);
    TextBox txtbox = (TextBox)ctrls[i];
    arr[i] = txtbox.Text;
    }
     
    I hope this coding helps to get values from dynamically created texboxes
    0