c# – Programatically set OnSelectedIndexChanged for a ddl – Education Career Blog

a minor question but it’s driving me nuts. I’m programatically generating about 50 DDLs based on a database schema (i.e. item 1 can do a,b,c item 2 can do d, e, a, etc etc).

If I was just writing the markup, I could specify:


and be done with it, unfortunately, I’m just not sure how to set that programatically. I found a “SelectedIndexChanged” event, but I’m not sure what I need to return in terms of an event handler when all I want to do is set the method called. I realize I could write 50 methods:

etc etc

but that solution isn’t terribly flexible, especially when I really only want the same method called. Is there a good way to accomplish what I’m trying to do here? Any input is greatly appreciated. Thanks.


You can set it from your code behind

DropDownList1.SelectedIndexChanged += new EventHandler ( funTimes ); 

You can set this from the Page_Load EventHandler or even from within the funTimes EventHandler.

Leave a Comment