Solved

Help displaying ASP Listbox selection

Posted on 2011-03-23
6
360 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
  • 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

19 Experts available now in Live!

Get 1:1 Help Now