2012-09-19 22 views
1

我有動態下拉控件的asp.net頁面,我只需要selectedIndexchanged事件觸發僅用於用戶選擇。ASP.NET下拉列表selectedindex更改爲方案選擇更改發射

目前selectedIndexchanged事件是針對每個編程性選擇更改觸發的。

有人可以建議如何檢查/觸發selectedIndexchanged事件只有「用戶」選擇?

+0

你有你控制 –

+0

要補充項目下拉列表逐一創建一個事件處理程序? – codingbiz

+0

是的,我正在逐個添加。但該事件應該只會觸發用戶選擇。基於用戶選擇,我正在以編程方式調整其他下拉值,所以現在甚至會引發程序化選擇更改。有人可以建議如何只獲取selectedindexchanged僅用於用戶選擇。 – AProgrammer

回答

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"); 
} 
+0

其實我是按照相同的代碼,我需要根據用戶選擇更改其他下拉值 例如我有5個下拉選擇值1到5,如果使用選擇第一個下拉值到5然後我需要更改其他選定的值以編程方式。 因此,我需要的是,僅針對**用戶選擇**而選擇僅更改事件觸發器,並且它不應觸發事件以進行編程選擇更改。 – AProgrammer