DDL not firing

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
Thanks Dan. Runat="server" is ok, but there is no reference to an event in
the InitialiseComponent sub. What should I put?
 
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
 
<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>
 
<asp:DropDownList ID="DDL1" Runat="server" AutoPostBack="true">

</asp:DropDownList>



Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
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
 
Back
Top