Drop down list OnSelectedIndexChanged without .aspx page

Sharepoint is very keen on using CAML to add controls to your pages. Which means the traditional way of adding an event handler to your asp:DropDownList tag isn't available. (as far as I can tell, anyway.)

So, here's how to work around this in your code behind:

ddlSort.AutoPostBack = true;
ddlSort.SelectedIndexChanged += new EventHandler(ddlSort_SelectedIndexChanged);
this.Controls.Add(ddlSort);