DDL not firing

G

Guest

How do I get a Dropdownlist to fire when the user selects an element? My
code is:

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

Dim selectedItem = DropDownList1.SelectedValue
Me.Label1.Text = "" + selectedItem + ""
End Sub
 
G

Guest

Hi Niggy,

Make sure your asp:dropdownlist tag has the runat="server" atrribute, and
that the event is wired up correctly in the InitialiseComponent sub.

HTH


Dan
 
G

Guest

Thanks Dan. Runat="server" is ok, but there is no reference to an event in
the InitialiseComponent sub. What should I put?
 
G

Guest

Hi Niggy,

In C#, I would write the following line in InitialiseComponent...

this.DropDownList1.SelectedIndexChanged += new
System.EventHandler(this.yourfunction)

I'm not sure of the VB syntax though, sorry!

Dan
 
G

Guest

<asp:dropdownlist id=DropDownList3 style="Z-INDEX: 104; LEFT: 120px;
POSITION: absolute; TOP: 336px" runat="server" DataMember="operators"
DataSource="<%# DataSet21 %>" DataTextField="Username"
DataValueField="Customer_id" AutoPostBack="True"></asp:dropdownlist>
 
J

Juan T. Llibre

<asp:DropDownList ID="DDL1" Runat="server" AutoPostBack="true">

</asp:DropDownList>
 
E

Eliyahu Goldin

Don't put anything there. It is supposed to be autocreated. Either go to
designer view, open the ddl properties and set the event there, or, even
better, in the html view add an event handler attribute to the ddl tag as
OnSelectedIndexChanged = DropDownList1_SelectedIndexChanged. And make
DropDownList1_SelectedIndexChanged Protected instead of Private.

Eliyahu
 

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

No members online now.

Forum statistics

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

Latest Threads

Top