S
Sameeksha
I've created the following control and placed it on a web page. When I click
on 'Add' button, it should add a new item to the dropdown list, but that's
not happening. Can anybody tell what's wrong with this code?
public class TryControl : System.Web.UI.WebControls.WebControl
{
protected DropDownList lst;
protected Button btn;
protected override void CreateChildControls()
{
base.CreateChildControls ();
lst = new DropDownList();
Controls.Add(lst);
if (!Page.IsPostBack)
{
lst.Items.Add("One");
lst.Items.Add("Two");
lst.Items.Add("Three");
}
btn = new Button();
Controls.Add(btn);
btn.Text = "Add";
btn.Click += new EventHandler(btn_Click);
}
private void btn_Click(object sender, EventArgs e)
{
lst.Items.Add("Next");
}
}
on 'Add' button, it should add a new item to the dropdown list, but that's
not happening. Can anybody tell what's wrong with this code?
public class TryControl : System.Web.UI.WebControls.WebControl
{
protected DropDownList lst;
protected Button btn;
protected override void CreateChildControls()
{
base.CreateChildControls ();
lst = new DropDownList();
Controls.Add(lst);
if (!Page.IsPostBack)
{
lst.Items.Add("One");
lst.Items.Add("Two");
lst.Items.Add("Three");
}
btn = new Button();
Controls.Add(btn);
btn.Text = "Add";
btn.Click += new EventHandler(btn_Click);
}
private void btn_Click(object sender, EventArgs e)
{
lst.Items.Add("Next");
}
}