Solved

Help displaying ASP Listbox selection

Posted on 2011-03-23
6
364 Views
Last Modified: 2012-08-13
I used code behind so I have two files.  Can anyone help me out as to why when I click the populated selections it is not displayed in the ASP labels below the listbox?  Im not good with VB and im thinking my error is in the aspx.vb script.

Thanks for any help in advance.


<code>
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="afFishing1.aspx.vb" Inherits="afFishing1" Debug = "true" %>

<!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></title>
    <style type="text/css">
        .style1
        {            font-size: medium;        }
        .alignRight
        {     font-weight:bold; color:Blue; text-align:right;        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div style="font-size: x-large">
   
        Fishing Reels<br />
        <br />
   
        <asp:ListBox ID="lstReels" runat="server" Width = "650px" BackColor="#33CCFF"
            Rows="10" AutoPostBack="True">
        </asp:ListBox>
   
        <br />
        <br />
        <span class="style1">You Selected: </span>
        <asp:Label ID="lblSelected" runat="server" style="font-size: medium"
            Width="554px"></asp:Label>
        <br />
        <br />
        <span class="style1">Price of your selected reel is:</span>
        <span class=alignRight><asp:TextBox ID="txtPrice" runat="server" ReadOnly="True"
            style="font-size: medium" Width="243px" AutoPostBack="True"></asp:TextBox></span>
        <br />
   
    </div>
           
       
       
   
    </form>
</body>
</html>
</code>

<code>
Option Explicit On
Option Strict On
Partial Class afFishing1
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then

            lstReels.Items.Add(New ListItem("Bass Pro Shops Johnny Morris Elite Baitcast Reels", "JME"))
            lstReels.Items.Add(New ListItem("Bass Pro Shops Extreme Baitcast Reels", "EXT"))
            lstReels.Items.Add(New ListItem("Bass Pro Shops Bionic Plus Baitcast Reel", "BPB"))
            lstReels.Items.Add(New ListItem("Shimano Stella FD Spinning Reel from Cabela's", "FDS"))
            lstReels.Items.Add(New ListItem("Cabela's Tournament ZX Spinning Reel", "TZX"))
            lstReels.Items.Add(New ListItem("Pflueger Supreme Spinning Reel from Cabela's", "PSS"))
        End If




    End Sub


 
    Protected Sub txtPrice_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPrice.TextChanged

        Dim Price As Double = 0.0
        Price = CType(txtPrice.Text, Double)

        Select Case lstReels.SelectedItem.Value
            Case "JME"
                Price = 120.43
                lblSelected.Text = "Bass Pro Shops Johnny Morris Elite Baitcast Reels"
            Case "EXT"
                Price = 210.89
                lblSelected.Text = "Bass Pro Shops Extreme Baitcast Reels"
            Case "BPB"
                Price = 320.99
                lblSelected.Text = "Bass Pro Shops Bionic Plus Baitcast Reel"
            Case "FDS"
                Price = 401.89
                lblSelected.Text = "Shimano Stella FD Spinning Reel from Cabela's"
            Case "TZX"
                Price = 501.89
                lblSelected.Text = "Cabela's Tournament ZX Spinning Reel"
            Case "PSS"
                Price = 603.22
                lblSelected.Text = "Pflueger Supreme Spinning Reel from Cabela's"


        End Select
    End Sub
End Class
</code>
0
Comment
Question by:networknoobaf24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 250 total points
ID: 35199000
You appear to have an event handler for the "TextChanged" event of your textbox, rather than a SelectedIndexChanged handler for your listbox.

Try changing;
Protected Sub txtPrice_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPrice.TextChanged

Open in new window

To:
Protected Sub lstReels_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstReels.SelectedIndexChanged

Open in new window

0
 
LVL 13

Assisted Solution

by:gamarrojgq
gamarrojgq earned 250 total points
ID: 35199061
Hi,

You have 2 problems

1.- The code that set the lblSelected Label is in the TXTPrice TextChange Event but this event would not be executed since your textbox is ReadOnly

2.- You do not have a SelectedIndexChanged Event on you Listbox where is the place where you should put the code to set the lblSelected Labe Text property

Hope that helps
l
0
 

Author Comment

by:networknoobaf24
ID: 35199460
I changed my controls around a bit and I get a result in the ASP LABEL but nothing in the txtPrice Read only box.  I don't understand what is wrong here?  Thanks again
Option Explicit On
Option Strict On
Partial Class afFishing1
    Inherits System.Web.UI.Page

    'afFishing.aspx.vb by networknoobaf24

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            'populate list box
            lstReels.Items.Add(New ListItem("Bass Pro Shops Johnny Morris Elite Baitcast Reels", "JME"))
            lstReels.Items.Add(New ListItem("Bass Pro Shops Extreme Baitcast Reels", "EXT"))
            lstReels.Items.Add(New ListItem("Bass Pro Shops Bionic Plus Baitcast Reel", "BPB"))
            lstReels.Items.Add(New ListItem("Shimano Stella FD Spinning Reel from Cabela's", "FDS"))
            lstReels.Items.Add(New ListItem("Cabela's Tournament ZX Spinning Reel", "TZX"))
            lstReels.Items.Add(New ListItem("Pflueger Supreme Spinning Reel from Cabela's", "PSS"))
        End If




    End Sub


    Protected Sub lstReels_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstReels.SelectedIndexChanged
        'declare variable price as double precision
        Dim dblPrice As Double
        Dim strPrice As String

        strPrice = Request.QueryString("txtPrice")
        dblPrice = CType(strPrice, Double)

        Select Case lstReels.SelectedItem.Value
            Case "JME"
                dblPrice = 120.43
                lblSelected.Text = "Bass Pro Shops Johnny Morris Elite Baitcast Reels"
            Case "EXT"
                dblPrice = 210.89
                lblSelected.Text = "Bass Pro Shops Extreme Baitcast Reels"
            Case "BPB"
                dblPrice = 320.99
                lblSelected.Text = "Bass Pro Shops Bionic Plus Baitcast Reel"
            Case "FDS"
                dblPrice = 401.89
                lblSelected.Text = "Shimano Stella FD Spinning Reel from Cabela's"
            Case "TZX"
                dblPrice = 501.89
                lblSelected.Text = "Cabela's Tournament ZX Spinning Reel"
            Case "PSS"
                dblPrice = 603.22
                lblSelected.Text = "Pflueger Supreme Spinning Reel from Cabela's"

        End Select
    End Sub
End Class

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Assisted Solution

by:gamarrojgq
gamarrojgq earned 250 total points
ID: 35199478
ok, you have to assign the value of you dblPrice variable to the textbox so after you  END SELECT line att this

txtPrice.Text = dblPrice.ToString
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 250 total points
ID: 35199492
You are putting the price into a variable, but you never write its value to the control. Add the following line immediately after End Select
txtPrice.Text = dblPrice.ToString()

Open in new window

0
 

Author Closing Comment

by:networknoobaf24
ID: 35199745
Thank you both, I am trying to learn to develop pages with Visual Studio, but it looks like i need to polish my coding skills
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

749 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