PDA

View Full Version : [c#] Calling TextBox dynamically


MRMAN
06-23-2006, 12:48 PM
howdy.

I have a form with over 30 text boxes on.
15 are called inputbox... (where ... is a number from 1 to 15)
and 15 are called outputbox... (where ... is a number from 1 to 15)

now in PHP you would be able to call the information using a variable variable
something like this.


for($counter = 1; $counter <= 15; $counter++)
{
$variablename = "inputbox".$counter;
$text = $_POST[$$variablename];
$variable2 = "outbutbox".$counter;
$$variable2 = $text;

}


so i was wondering if there is a way i can do something similar in c#

Cheers.

MRMAN

oracleguy
06-23-2006, 06:02 PM
That PHP example is a little different. The controls on your form, are they each in control arrays? Like all the inputboxes are in an array together?

MRMAN
06-28-2006, 11:51 AM
Thank you i managered to sort it.
If any one is interested this is what i did


public void GetEmpName(TextBox textboxname)
{
other code
//function call
TextBox textboxname2 = FindTextBox(text);
other code
}


private TextBox FindTextBox(string sName)
{
foreach(TextBox MyTextBox in this.Controls)
{
// MessageBox.Show(MyTextBox.Name.ToString());
if (MyTextBox.Name == sName)
{
return MyTextBox;
}
}
return null;
}