いくつかのランタイム変数の値に基づいていくつかのボタンを作成しています (いくつあるかもわかりません)。
ボタンの私のコードは次のとおりです。
Button cancel = new Button();
cancel.Text = "Cancel";
cancel.ID = "cancelEnrollmentForStudent" + zapsanePredmetyList.ElementAt(i).ID.ToString() + "-" + i ;
cancel.Click += new EventHandler(cancelEnrollment);
string toCancel = selectedSubject.SelectedValue + ";" + studentToEnroll.SelectedValue;
cancel.CommandArgument = toCancel;
クリックメソッドのコードは
protected void cancelEnrollment(object sender, EventArgs e)
{
//do something when button clicked.
Button sourceButton = (Button)sender;
string[] data = sourceButton.CommandArgument.Split(';');
}
ただし、ボタンがクリックされたときにクリック メソッドが起動しません。これは、実行時にボタンを作成するという事実と関係があると思います。このメソッドを起動する方法について誰かがアドバイスしますか?
ありがとう、オンドレイ