1

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

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

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

4

1 回答 1

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");
}
于 2012-09-19T23:07:50.943 回答