[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Drop List

Posted on 2011-10-19
3
Medium Priority
?
159 Views
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 vb.net
0
Comment
Question by:jordanhelen
3 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 2000 total points
ID: 36993358
Put this into the HEAD section of the HTML part of the page:
<script type="text/javascript">
    function comboChange(combo) {
        document.getElementById('<%=Me.Label1.ClientID%>').innerHTML = combo.value;
    }
</script>

And put this into the Page_Load method:
Me.DropDownList1.Attributes.Add("onchange", "comboChange(this)")

Obviously, replace "Label1" and "DropDownList1" with your controls' names.

Hope that helps.
0
 
LVL 2

Expert Comment

by:owaisyahya
ID: 36993457
You should do it with javascript.

<%@ 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>
    <script type="text/javascript">
        function displayvalue(obj)
        {
            document.getElementById('<%=Label1.ClientID%>').innerHTML=obj.value;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem Text="A" Value="A"></asp:ListItem>
            <asp:ListItem Text="B" Value="B"></asp:ListItem>
            <asp:ListItem Text="C" Value="C"></asp:ListItem>
            <asp:ListItem Text="D" Value="D"></asp:ListItem>
        </asp:DropDownList>    
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

Open in new window


Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            DropDownList1.Attributes.Add("onchange", "displayvalue(this)")
        End If
    End Sub
End Class

Open in new window

0
 
LVL 20

Expert Comment

by:ddayx10
ID: 36996109
I agree you can and may want to do this with JS, but if by chance you want to do it the way you originally asked it can be done like this:

<<see code>>
****ASPX PAGE****
<asp:DropDownList ID="ddl1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddl1_SelectedIndexChanged">
	<asp:ListItem value="-1" Text="Choose" />
	<asp:ListItem value="0" Text="Zero" />
	<asp:ListItem value="1" Text="One" />
</asp:DropDownList>
<asp:Label ID="lbl1" runat="server" />

***CODE BEHIND***
Protected Sub ddl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
   If ddl1.SelectedValue > -1 Then
      lbl1.Text = String.Format("Text={0} AND Value={1}", ddl1.SelectedItem.Text, ddl1.SelectedItem.Value)
   Else
      lbl1.Text = String.Empty
   End If
End Sub

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

865 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