Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to fire dropdownlist.selectedindexchanged event programmatically

Tags:

asp.net

I have some code which fires when user selects 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.

like image 770
Rohit Raghuvansi Avatar asked Apr 21 '10 07:04

Rohit Raghuvansi


2 Answers

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

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

This should work.

like image 72
Sin Avatar answered Sep 23 '22 18:09

Sin


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);
like image 7
x2. Avatar answered Sep 23 '22 18:09

x2.