在代码中触发OnSelectedIndexChanged事件

hoa*_*key 0 c# asp.net events

除了从下拉列表中触发此事件之外,我还希望能够从我的代码中触发它.这有可能吗?如果可以的话怎么样?

谢谢

斯图

Iai*_*ard 5

执行此操作的最佳方法是将事件中的代码包装到方法中,并从两个位置调用它.

如果您确实想直接调用该事件(我不推荐),您可以这样做:

MyComboBox_SelectedIndexChanged(null, null);
Run Code Online (Sandbox Code Playgroud)

(除非你使用方法senderEventArgs方法,否则你也需要提供这些)