无论我做什么或尝试下拉列表不仅仅是工作,
<asp:DropDownList ID="drop1" runat="server" AutoPostBack="true" enabledviewstate="true" OnClick="Drop1_SelectedIndexChanged" />
在这里绑定它,
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDropDownList();
}
//drop1.SelectedIndexChanged += new EventHandler(Drop1_SelectedIndexChanged);
}
和这里的方法,从不触发(我使用断点检查)
protected void Drop1_SelectedIndexChanged(object sender, EventArgs e)
{
//checkboxlist1.Items.Add("hahahha");
}
还有什么选择???????????我需要使用
填充下拉列表 using (SqlDataSource ds = new SqlDataSource(ConnectionString(), SelectCommand()))
{
System.Data.DataView dv = (System.Data.DataView)ds.Select(DataSourceSelectArguments.Empty);
if (dv.Count > 0)
{
drop1.DataSource = ds;
drop1.DataTextField = "UserName";
drop1.DataBind();
drop1.Items.Insert(0, "Please select a Username ");
}
}
答案 0 :(得分:3)
Click
没有定义DropDownList
个事件。要使用的事件是SelectedIndexChanged:
<asp:DropDownList ID="drop1" runat="server"
AutoPostBack="true"
EnabledViewState="true"
OnSelectedIndexChanged="Drop1_SelectedIndexChanged" />
答案 1 :(得分:1)
而是OnSelectedIndexChanged
您键入了OnClick
按如下方式声明下拉列表:
<asp:DropDownList ID="drop1" runat="server" AutoPostBack="true" enabledviewstate="true" OnSelectedIndexChanged="Drop1_SelectedIndexChanged" />
答案 2 :(得分:1)
Dropdownlist中没有Onclick事件为Dropdownlist使用OnSelectedIndexChanged事件。