Hello again friends

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

Thanks

From javascript or from server side and in what language?(C#,c++,VB)

Thanks for your help.

I´d like to use JavaScript using VB.

Thanks a lot

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.