Hello ,
Here is the sample code. Just take the combobox/Dropdown & list the control which you want to Create Dynamically & assign some value.
Take the Button to execute the code on Click.
For Example textbox as value 1,label as value 2
and Call Function CreateControl() & apply swith case.
Here is the small Code;
Take one integer as global variable
int cleft = 1;
the variable is for the positioning purpose.
Then Modify your function CreateControl()
<pre lang="c#">private void CreateControl()
{
switch (urDropdown.selectedvaue)
{
case 1:
Button myButton = new Button();
this.Controls.Add(myButton);
myButton.Top = cleft * 25;
myButton.Left = 100;
myButton.Text = "TextBox " + this.cleft.ToString();
cleft++;
break;
case 2:
Label label1 = new Label();
this.Controls.Add(label1);
label1.Top = cleft * 25;
label1.Left = 100;
label1.Text = "label1 " + this.cleft.ToString();
cleft++;
break;
case 3:
break;
default:
}
}
The code is for LAbel & Textbox.your expand it to any number of controls you want.You can take it for textbox,combobox,Groupbox,panel & so on .
Kindly take try, catch in your code to catch any error when it occurs.
Let me know whether this helped you or not.?
Happy Coding :-)