Hello,
I need to add child control(a textbox) based on the selected value of the dropdown list.I have done something like
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(DropDownList1.SelectedIndex==4)
{
TextBox txt = new TextBox();
DropDownList1.Controls.Add(txt);
}
}
The above code gives the error saying,
'System.Web.UI.WebControls.DropDownList' does not allow child controls.
Any Help..?????
Thanks
Regards,
Soumya
Adding child control to dropdownlist control
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

jake shi6 reputationPosted Apr 1, 2008, 6:39 PM EDT
if you want to add child controls to dropdownlist ,you must inherit the base class:system.web.ui.control,and implement the interface:INamingContainer,
then you can override the base class's method:CreateChildControls.In this method you can do like this Control.Add(your textbox's name)
you can try it . good luck.
suhail ahmed6 reputationPosted Apr 1, 2008, 10:02 PM EDT
can you please reply me with the code snippet.
I am facing difficulty how to use and override that method.
thnx in advance
soumya p n39 reputationPosted Apr 1, 2008, 10:43 PM EDT