Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DropDownList and Radio button selections perform calculation to a text box

Posted on 2011-03-23
6
Medium Priority
?
355 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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

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!

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

824 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