Click to See Complete Forum and Search --> : [RESOLVED] Adding an Event at runtime C#


Bill Crawley
February 23rd, 2009, 01:07 PM
Hi All,

I have the following signature for a function:

protected void Option_SelectedIndexChanged(object sender, EventArgs e)
{.......}
in another event Im creating a buttonlist control:

RadioButtonList myradiobuttonlist = new RadioButtonList();
myradiobuttonlist.AutoPostBack = true;
myradiobuttonlist.ID = "RoomOptionsRadioButtonList" + roomIndex.ToString();
I need to bind myradiobuttonlist SelectedIndexChanged event to my method above, how do I do that please. I thought it might be the following, but the compiler doesn't like it.

myradiobuttonlist.SelectedIndexChanged += new Option_SelectedIndexChanged(myradiobuttonlist,new System.EventArgs);

Although I think I need to Bind to the Option_SelectedIndexChanged event, it might be ok if it has it's own event and this event calls Option_SelectedIndexChanged.

dannystommen
February 25th, 2009, 07:54 AM
Change it to

myradiobuttonlist.SelectedIndexChanged += new EventHandler(Option_SelectedIndexChanged);

Bill Crawley
February 27th, 2009, 03:30 AM
Thanks, that did the trick. I was over complicating it with trying to use delegates. Doh!...