Solved

Help displaying ASP Listbox selection

Posted on 2011-03-23
6
361 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

26 Experts available now in Live!

Get 1:1 Help Now