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
Loading
soumya p nPosted Apr 2, 2008, 2:43 AM
suhail ahmedPosted Apr 2, 2008, 2:02 AM
can you please reply me with the code snippet.
I am facing difficulty how to use and override that method.
thnx in advance
jake shiPosted Apr 1, 2008, 10:39 PM
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.