无论我做什么或尝试,下拉列表都不起作用,
<asp:DropDownList ID="drop1" runat="server" AutoPostBack="true" enabledviewstate="true" OnClick="Drop1_SelectedIndexChanged" />
将其绑定(bind)到此处,
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 ");
}
}
最佳答案
没有为 DropDownList
定义 Click
事件。要使用的事件是 SelectedIndexChanged :
<asp:DropDownList ID="drop1" runat="server"
AutoPostBack="true"
EnabledViewState="true"
OnSelectedIndexChanged="Drop1_SelectedIndexChanged" />
关于c# - ASP.NET 下拉列表的替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16460728/