2011-12-30 11 views
0

我有一個複選框,表明通信地址下拉列表的事件是一樣的永久地址。有4個dropdownlists -的SelectedIndexChanged()在checkbobx檢查

  1. DRP_Comm_Country1
  2. DRP_Comm_State1
  3. DRP_Per_Country2
  4. DRP_Per_State2

當我選中該複選框,永久地址dropdownlists的項目應該是相同的通信地址dropdownlists.How使它成爲可能?

我的代碼是

protected void CheckBox2_CheckedChanged(object sender, EventArgs e) 
{ 
    DRP_Per_Country2.SelectedIndex = DRP_Comm_Country1.SelectedIndex; 
} 

DRP_Per_Country2SelectedIndexChanged()事件沒有得到fired.Is它一個錯誤的方法?如果是這樣,如何工作呢?

+0

DRP_Per_Country2.Text = DRP_Comm_Country1.Text; – Sandy 2011-12-30 09:36:08

+0

@rapsalands ......然後DRP_Per_State2將無法正常工作 – sun 2011-12-30 09:39:10

回答

2

首先,你必須設置

AutoPostBack = true 

財產所有DropDownList。如果這不會工作,然後調用SelectedIndexChanged事件手動

protected void CheckBox2_CheckedChanged(object sender, EventArgs e) 
{ 
    DRP_Per_Country2.SelectedIndex = DRP_Comm_Country1.SelectedIndex; 
    DRP_Per_Country2_SelectedIndexChanged(sender,e); 
} 

這必將觸發事件。

+0

@kishorejangid ...讓我試試吧 – sun 2011-12-30 09:42:59

+0

其更好地封裝indexchange內的代碼作爲一種方法和顯式調用方法。 IMO事件處理程序只應作爲事件的結果被調用。 [查看燒燬的手指(http://stackoverflow.com/a/6545857/570150) – V4Vendetta 2011-12-30 09:43:30

+0

接受的答案,如果你的作品,感謝您的答覆。 – 2011-12-30 09:47:31

相關問題