Drop down list 101

K

Kivak Wolf

Hi all,

I have a drop down list with a few members in it (prepopulated by
hardcode in the HTML), how would I know what the value of the selected
item was when the user picks one? I know it has to do with "Handles
myDDL.SelectedIndexChanged" but I don't know the correct syntax for the
whole function.

Thanks,
Kivak
 
K

Ken Cox [Microsoft MVP]

Hi Kivak,

It is going to look something like this in VB.

Ken
Microsoft MVP [ASP.NET]


<%@ Page Language="VB" %>


<script runat="server">


Protected Sub DropDownList1_SelectedIndexChanged _
(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = DropDownList1.SelectedItem.Value
End Sub
</script>

<html>

<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
</asp:DropDownList><br />
<asp:Label ID="Label1" runat="server"
Text=""></asp:Label>&nbsp;</div>
</form>
</body>
</html>
 

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
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top