Solved

DropDownList and Radio button selections perform calculation to a text box

Posted on 2011-03-23
6
344 Views
Last Modified: 2012-05-11
Ok this is my last cry for help.  I have spent a few days on this and I don't know where I'm wrong.  Any help would be greatly appreciated.  Thanks again.

This is another code behind page
Option Explicit On
Option Strict On

Partial Class afDeepSea2
    Inherits System.Web.UI.Page


    'Event handler checks to see if radio buttons have been changed and displays the Image according to the selection
    Protected Sub showImage(ByVal sender As Object, ByVal e As System.EventArgs) Handles radOcean.CheckedChanged, radMarlin.CheckedChanged, radPearl.CheckedChanged
        If radOcean.Checked Then
            imgBox.ImageUrl = "./images/Ocean.jpg"
        End If

        If radMarlin.Checked Then
            imgBox.ImageUrl = "./images/Marlin.jpg"
        End If

        If radPearl.Checked Then
            imgBox.ImageUrl = "./images/Pearl.jpg"
        End If


    End Sub
    Protected Sub showPrice(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlDays.SelectedIndexChanged, radMarlin.CheckedChanged, radOcean.CheckedChanged, radPearl.CheckedChanged
        'declare variable price as double precision
        Dim dblPrice As Double
        Dim strPrice As String

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

        If radOcean.Checked Then
            Select Case ddlDays.SelectedItem.Value
                Case "1"
                    dblPrice = 1500
                Case "2"
                    dblPrice = 1700
                Case "3"
                    dblPrice = 3500
            End Select
        End If

        If radMarlin.Checked Then
            Select Case ddlDays.SelectedItem.Value
                Case "1"
                    dblPrice = 1500
                Case "2"
                    dblPrice = 1700
                Case "3"
                    dblPrice = 3500
            End Select
        End If

        If radPearl.Checked Then
            Select Case ddlDays.SelectedItem.Value
                Case "1"
                    dblPrice = 1500
                Case "2"
                    dblPrice = 1700
                Case "3"
                    dblPrice = 3500
            End Select
        End If

        
            txtPrice.Text = dblPrice.ToString() 'assign dblPrice to the read only text box
    End Sub
End Class

Open in new window

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="afDeepSea2.aspx.vb" Inherits="afDeepSea2" 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>afDeepSea1.aspx by networknoobaf24</title>
 <style type="text/css">
        .firstTd
        {font-family: 'Arial Black';
	    font-size: 12pt;
	    color: blue;
	    width:200px;
	    padding-left:20px; }
        .controls  
        {font-family:'Arial Black'; font-size:12pt; color:blue; 
        text-align:right;background-color:yellow;}

  </style><!--CSS CLASS declarations-->
</head>


<body>
<img src = "./images/Costarica.jpg"></image><br />
<h2>afDeepSea2.aspx by networknoobaf24</h2>
    <form id="form1" runat="server">
    <!--create table-->
    <table border = "2">
    <tr>
    <td class ="firstTd"> 
        <br />
        Select a boat 
        <br />
        <br />
        <asp:RadioButton ID="radOcean" runat="server" AutoPostBack="True" 
            Text="Ocean:35ft" Checked="True" GroupName="showImage" />
        <br />
        <asp:RadioButton ID="radMarlin" runat="server" AutoPostBack="True" 
            Text="Marlin:40ft" GroupName="showImage" />
        <br />
        <asp:RadioButton ID="radPearl" runat="server" AutoPostBack="True" 
            Text="Pearl:57ft" GroupName="showImage" />
        <br /><br />

    </td>

    <td>
        <asp:Image ID="imgBox" runat="server" 
            ImageUrl="~/afChapter2/images/Ocean.jpg" /></td>
   
    </tr>
    <tr>
    <td>Select Number of Days:
        <asp:DropDownList ID="ddlDays" runat="server" AutoPostBack="True" 
            CssClass="controls">
            <asp:ListItem Text="1 day" Value="1" Selected="True">1 days</asp:ListItem>
            <asp:ListItem Value="2">2 days</asp:ListItem>
            <asp:ListItem Value="3">3 days</asp:ListItem>
        </asp:DropDownList>
    </td>
    <td>
        Price:<asp:TextBox ID="txtPrice" runat="server" 
            ReadOnly="True" CssClass="controls">$1500.00/day</asp:TextBox></td>
    </tr>
    </table>
    
    
    </form>
</body>
</html>

Open in new window

0
Comment
Question by:networknoobaf24
  • 3
  • 2
6 Comments
 

Author Comment

by:networknoobaf24
ID: 35200141
WOW im brain dead.  My problem is that I can't get the price to display in the text box txtPrice.

if someone selects Ocean for 3 days the total should be $4500.  ($1500 per day)
(1700 per day for Marlin and 3500 per day for Pearl)  Then depending on the number of days the price is displayed.
0
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 500 total points
ID: 35200215
       If radOcean.Checked Then
            Select Case ddlDays.SelectedItem.Value
                Case "1"
                    dblPrice = 1500
                Case "2"
                    dblPrice = 1700
                Case "3"
                    dblPrice = 3500
            End Select
        End If

        If radMarlin.Checked Then
            Select Case ddlDays.SelectedItem.Value
                Case "1"
                    dblPrice = 1500
                Case "2"
                    dblPrice = 1700
                Case "3"
                    dblPrice = 3500
            End Select
        End If

        If radPearl.Checked Then
            Select Case ddlDays.SelectedItem.Value
                Case "1"
                    dblPrice = 1500
                Case "2"
                    dblPrice = 1700
                Case "3"
                    dblPrice = 3500
            End Select
        End If

Your prices are the same, it doesn't matter if radOcean.checked or radMarlin.checked or radPearl.checked.

Hope that helps.
0
 
LVL 7

Expert Comment

by:nbove
ID: 35200242
Change your event handler to the following:
Dim days as Integer = Integer.Parse(ddlDays.SelectedValue)
If radOcean.Checked Then
  imgBox.ImageUrl = "./images/Ocean.jpg"
  txtPrice.Text = String.Format("{0:C}", 1500 * days)
End If
If radMarlin.Checked Then
  imgBox.ImageUrl = "./images/Marlin.jpg"
  txtPrice.Text = String.Format("{0:C}", 1700 * days)
End If
If radPearl.Checked Then
  imgBox.ImageUrl = "./images/Pearl.jpg"
  txtPrice.Text = String.Format("{0:C}", 3500 * days)
End If

Open in new window

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 7

Expert Comment

by:nbove
ID: 35200326
Alternatively, you can change your showPrice method to the following:
        Dim dblPrice As Integer
        If radMarlin.Checked Then
          dblPrice = 1700
        End If
        If radOcean.Checked Then
          dblPrice = 1500
        End If
        If radPearl.Checked Then
          dblPrice = 3500
        End If
        
        Dim intDays as Integer = CType(strPrice, Double)
        Dim total as Integer = Price * Days
        txtPrice.Text = total.ToString()

Open in new window

0
 
LVL 7

Expert Comment

by:nbove
ID: 35200330
I'm sorry line 12 should be
Dim intDays as Integer = CType(ddlDays.SelectedValue, Integer)

Open in new window


0
 

Author Closing Comment

by:networknoobaf24
ID: 35200765
unbelievable.  how dumb! that is what happens when i work on stuff too long.  thank you so much
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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

13 Experts available now in Live!

Get 1:1 Help Now