Help displaying ASP Listbox selection

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>
networknoobaf24Asked:
Who is Participating?
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
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
 
gamarrojgqConnect With a Mentor Commented:
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
 
networknoobaf24Author Commented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
gamarrojgqConnect With a Mentor Commented:
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
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
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
 
networknoobaf24Author Commented:
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
All Courses

From novice to tech pro — start learning today.