Menu

How to manually call a dropdown list selected index changed event?

Written by

Solution:1

DropDownlist selected index changed cannot be trigged programmatically. You have to set the selected index of that ddl and call selected index changed event

ddl.SelectedIndex = 2;
ddl_SelectedIndexChanged(null,null);

Solution:2

write a method that does what needs to be done when the selected index changes, don’t make it the selected index changed method.

Call that method when the selectedindex changes.

when you use the querystring to do something, set the index of the drop down list and call the same method the selectedindexchanged method calls.

you could call the method by name using the parameters in your event, but you really don’t need to.  If you are using visual studio, you can highlight the code in the selectedindexchanged event, right-click and select refactor / extract method.  This is a quick way to move the code to another method.

Article Categories:
.Net (C#/VB)

Comments are closed.

Shares