ASP.NET下拉列表selectedindex更改触发程序选择更改

时间:2012-09-19 22:50:16

标签: asp.net drop-down-menu selectedindexchanged

我有带动态下拉控件的asp.net页面,我只需要为用户选择启动selectedIndexchanged事件。

目前selectedIndexchanged事件正在为每个编程选择更改而触发。

有人可以建议如何检查/触发selectedIndexchanged事件只选择“用户”吗?

1 个答案:

答案 0 :(得分:0)

我希望这对你有用

protected void Page_Load(object sender, System.EventArgs  e){

    DropDownList cbTest = new DropDownList();
    cbTest.ID = "cbot";
    //create an event handler for the SelectedIndexChanged event
    cbTest.SelectedIndexChanged += new EventHandler(cbt_SelectedIndexChanged);        
    cbTest.Items.Add("1");
    cbTest.Items.Add("2");
    cbTest.Items.Add("3");
    //set the AutoPostBack property to sends the data back to the server
    cbTest.AutoPostBack = true;
    this.form1.Controls.Add(cbTest);

}
//handle the selections made by the User
void cbt_SelectedIndexChanged(object sender, EventArgs e)
{
    Response.Write("This works");
}