• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

drop list values

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 vb.net
0
jordanhelen
Asked:
jordanhelen
  • 2
1 Solution
 
Rajkumar GsSoftware EngineerCommented:
ASPX Page Code
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
            <asp:ListItem Text="India" Value="1"></asp:ListItem>
            <asp:ListItem Text="Pakistan" Value="2"></asp:ListItem>
        </asp:DropDownList>
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

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 ?
Raj
0
 
Rajkumar GsSoftware EngineerCommented:
If yes, remember to enable AutoPostBack property of Dropdownlist. and write code in SelectedIndexChanged event as shown above.

Raj
0
 
disruptCommented:
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="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>

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

Open in new window

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now