Unable to add SelectedIndexChanged event from code behind

S

Shawn

I have a DataGrid with only one TemplateColumn wich contains a DropDownList.
After I bind the DataGrid I fill the dropDownLists with values in
ItemDataBound. None of the DropDownLists contains the same values. Some of
these DropDownLists have AutoPostBack set to true, but I'm having trouble
adding the SelectedIndexChanged event to them. This is my code:
ddlParameterValue = dataGridItem.FindControl("ddlParameterValue")
ddlParameterValue.AutoPostBack = True
AddHandler ddlParameterValue.SelectedIndexChanged, New
System.EventHandler(AddressOf ddlParameterValue_SelectedIndexChanged)


Public Sub ddlParameterValue_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
....
End Sub

I put a brakepoint on the method, but it never gets called. The
AutoPostBack part works fine.

Any ideas?

Shawn
 
P

Patrick.O.Ige

About this
Public Sub ddlParameterValue_SelectedIndexChanged(ByVal sender As
Object,ByVal e As System.EventArgs) DDL.SelectedIndexChanged
Patrick
 
D

Damien

Shawn said:
I have a DataGrid with only one TemplateColumn wich contains a DropDownList.
After I bind the DataGrid I fill the dropDownLists with values in
ItemDataBound. None of the DropDownLists contains the same values. Some of
these DropDownLists have AutoPostBack set to true, but I'm having trouble
adding the SelectedIndexChanged event to them. This is my code:
ddlParameterValue = dataGridItem.FindControl("ddlParameterValue")
ddlParameterValue.AutoPostBack = True
AddHandler ddlParameterValue.SelectedIndexChanged, New
System.EventHandler(AddressOf ddlParameterValue_SelectedIndexChanged)


Public Sub ddlParameterValue_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
...
End Sub

I put a brakepoint on the method, but it never gets called. The
AutoPostBack part works fine.

Any ideas?

Shawn

Hi Shawn,

1) When are you adding the event handler,
2) Are other events working?

Even if the control exists already on the page, I believe you'd have to
make sure you add the handler during each page request (i.e. not just
the first time inside a If Not IsPostback block)

Damien
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top