开发者

how to fire dropdownlist.selectedindexchanged event programmatically

I have some code which fires when user sel开发者_运维百科ects an item in dropdownlist. Now I want the same code to fire when I set selectedindex programmatically.

I have tried setting

ddlSystemLevelDCP.SelectedIndex=2;

and this as well

ddlSystemLevelDCP.SelectedValue="2";

None of them fires this event. However when user changes the selection, this event fires.


Set your selected index. say, 2 and then call that event with null arguments.

ddlSystemLevelDCP.SelectedIndex=2;
ddlSystemLevelDCP_SelectedIndexChanged(null,null);

This should work.


If you have event handler, you can call it.

<asp:DropDownList ID="ddlSystemLevelDCP" runat="server"
AutoPostBack="true"
onselectedindexchanged="ddlSystemLevelDCP_SelectedIndexChanged">
</asp:DropDownList>
...
...
...
ddlSystemLevelDCP_SelectedIndexChanged(ddlSystemLevelDCP,EventArgs.Empty);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜