I have tried below code but it didn’t work:
DropDownList1.SelectedIndexChanged += new EventHandler ( doSub );
- It is in C# not VB
- When I type DropDownList1. intellisense doesn’t bring the SelectedIndexChanged method
- And last it complains about SelectedIndexChanged is an event and must be called by RaiseEvent
I’m trying to make ddls dynamically based on SelectedValue of each other, so I need to set the OnSelectedIndexChanged values programmatically instead of declarativly like this:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DoSub">
</asp:DropDownList>
Thanks in advance.
Tip: Remove the AutoEventWireup=”false” in @Page section to get solution to work.
Use AddHandler to attach an event handler.
Syntax:
Example: