0
這是一個快速的代碼片段,對我來說這似乎不起作用。我正在從文件中讀取以創建單選按鈕列表。問題是,當單擊其中一個單選按鈕時,我在代碼中設置的事件處理程序不會觸發。我已經在調試模式下用換行符反覆測試它......所有都沒有運氣。我在這裏錯過了明顯的東西嗎?動態添加的事件處理程序不會觸發
感謝高級!
strLine = strLine.Trim();
System.Diagnostics.Debug.WriteLine("[3-a] ship by date - date: " + strLine);
try{ shipByDate = (Convert.ToDateTime(strLine)); }
catch (Exception e) { shipByDate = new DateTime(); }
shipByDesc = sr.ReadLine().Trim();
System.Diagnostics.Debug.WriteLine("[3-b] ship by date - desc: " + shipByDesc);
RadioButton button = new RadioButton();
button.Text = shipByDesc + " - " + shipByDate.ToString("MM/dd/yyyy");
button.Checked = false;
button.GroupName = "shipByOptions";
button.ID = "shipByRadio" + count;
//button.EnableViewState = true;
button.AutoPostBack = true;
button.CheckedChanged += new EventHandler(shipBy_CheckedChanged); // <-- doesn't work!!!
//form1.Controls.Add(button);
shipByPlaceHolder.Controls.Add(button);
你搖滾Oded,感謝您的幫助。這正是問題所在。 – Ryan 2010-10-13 19:51:28
@Ryan不要忘記任命他一個「複選標記」然後:) – 2010-10-13 20:51:33
明白了,對不起,我對SO有點新鮮。檢查檢查檢查 – Ryan 2010-10-15 13:24:19