drop list values

Posted on 2011-10-19
Last Modified: 2012-05-12
I have a web page with a drop list that have values I want to take the value the user selects and put it in a lable using
Question by:jordanhelen
    LVL 23

    Accepted Solution

    ASPX Page Code
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <html xmlns="">
    <head runat="server">
        <title>Untitled Page</title>
        <form id="form1" runat="server">
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
                <asp:ListItem Text="India" Value="1"></asp:ListItem>
                <asp:ListItem Text="Pakistan" Value="2"></asp:ListItem>
            <br />
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    Open in new window

    Code-Behind Code
     Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
            Label1.Text = DropDownList1.SelectedItem.Text
        End Sub

    Open in new window

    Is this you are looking for ?
    LVL 23

    Expert Comment

    by:Rajkumar Gs
    If yes, remember to enable AutoPostBack property of Dropdownlist. and write code in SelectedIndexChanged event as shown above.

    LVL 16

    Expert Comment

    You can also use jquery something like so to get the value:

    var selected = $("#dropdownidhere option:selected").text();

    and to set the label:

    $('#<%= labelidhere.ClientID %>').text(selected);

    something like so:
    <script src="" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    var selected = $("#dropdownidhere option:selected").text();
                if(selected != "") 
                 $('#<%= labelidhere.ClientID %>').text(selected);

    Open in new window


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now