求在aspx.cs中用c#动态创建一个asp.net的dropdownlist的代码,让这个控件显示在页面上??????
private System.Web.UI.WebControls.DropDownList ddlYear;
protected void Page_Load(object sender, EventArgs e)
{
this.Controls.Clear();
ddlYear = new DropDownList();
ddlYear.ID = "ddlYear ";
ddlYear.Width = 54;
ddlYear.Items.Add(new ListItem( "11 "));
ddlYear.Visible = true;
this.Controls.Add(ddlYear);
}
我这样写报错,说要包含在form tag里
------解决方案--------------------this.Controls.Add
改成
Page.Form.Controls.Add