本文介绍了下拉列表中的SelectedIndexChanged在按钮的单击事件中未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void Button1_Click(object sender, EventArgs e)
{
TableRow tb = new TableRow();
TableCell tc=new TableCell();
DropDownList db = new DropDownList();
db.Items.Add("Bangalore");
db.Items.Add("Mandya");
db.Items.Add( "Hassan");
tc.Controls.Add(db);
tb.Controls.Add(tc);
Table1.Controls.Add(tb);
db.SelectedIndexChanged += db_SelectedIndexChanged;
db.AutoPostBack = true;
}
private void db_SelectedIndexChanged(object sender,EventArgs e)
{
label.text="welcome";
}
但是当我在页面加载事件db_SelectedIndexChanged执行中放置button_click的相同代码块时,将执行.
但是当我在Button中使用代码时,单击db_SelectedIndexChanged不会执行.
But when I place the same code block of button_click in page load event db_SelectedIndexChanged execute.
But when I use code in Button click db_SelectedIndexChanged doesn''t execute.
What may be the reason behind this?
推荐答案
protected void Button1_Click(object sender, EventArgs e)
{
db_SelectedIndexChanged(this, e);
}
这篇关于下拉列表中的SelectedIndexChanged在按钮的单击事件中未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!