?
Solved

DropDownList and Radio button selections perform calculation to a text box

Posted on 2011-03-23
6
Medium Priority
?
353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

718 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