1
votes

I have the control dropdownlist which has been loaded inside the template column of RadGrid.
While loading I have set AutoPostBack='True' for dropdownlist and also created the event SelectedIndexChanged.

 DropDownList ddlConditions = new DropDownList(); 
 ddlConditions.ID = "ddl" + name;
 ddlConditions.AutoPostBack = true;
 ddlConditions.SelectedIndexChanged += new EventHandler(ddlConditions_SelectedIndexChanged);

My question is while i change the selected index of dropdownlist the event SelectedIndexChanged is not getting triggered.
Can anyone help me to solve this problem?
Thanks in advance.

3

3 Answers

1
votes

Usually this caused by a page life cycle problem. When your index changed event of Dropdownlist fires the control doesn't exist to bind it on the postback.

Example:

-> MyEvent fires. -> Drop-down created. -> Event Handler specified. -> Index Changed event triggered. Page reloads. Drop-down not found, cannot fire.

So you have to ensure that the drop-down is created before .NET attempts to handle the event.

Please refer this answer for more information regarding this type of issue and life cycle.

1
votes

I can suggest you to check the place where you have created DropDownList. Dynamic controls should be added on OnInit or at least on OnLoad. After OnLoad finishes executing ASP.NET starts processing control's events and values.

My question is while i change the selected index of dropdownlist the event SelectedIndexChanged is not getting triggered.

Answer: because you have created DropDownList after the events have been processed.

0
votes

Is the page posting back? If so, you'll need to make sure that the control is recreated on the page on every postback.

If it's inside the usual if(!IsPostBack) block, then put it outside - Usually, it's prudent to create controls in page_init as well, but that can depend on your specific setup.