0

Hello again friends

Now I would like to know how to validate a DropDownList to know if an item was selected or not

Thanks

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by IdanS
0

Thanks for your help.

I´d like to use JavaScript using VB.

Thanks a lot

0

Hi,

On your DropDownList control you have a property that called "OnSelectedIndexChanged", What you need to do is assign the name of the method you want to call when a value is changed like that:

<asp:DropDownList id="DropDownList1" OnSelectedIndexChanged = "DropDownList_SelectedIndexChanged" runat="server">
                <asp:ListItem Value="1">1</asp:ListItem>
                <asp:ListItem Value="2">2</asp:ListItem>
                <asp:ListItem Value="3">3</asp:ListItem>
                <asp:ListItem Value="4">4</asp:ListItem>
                <asp:ListItem Value="5">5</asp:ListItem>
            </asp:DropDownList>

After you have done this you need to build your code in javascript likt this:

<script runat="server">
    Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
      Select Case DropDownList1.SelectedItem.Value
        Case 1: Label1.Text = "You have selected 1"
        Case 2: Label1.Text = "You have selected 2"
        Case 3: Label1.Text = "You have selected 3"
        Case 4: Label1.Text = "You have selected 4"
        Case 5: Label1.Text = "You have selected 5"
      End Select
    End Sub
</script>

Enjoy!

Edited by IdanS: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.