Solved

DropDownList and Radio button selections perform calculation to a text box

Posted on 2011-03-23
6
347 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
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 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

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

Suggested Solutions

Title # Comments Views Activity
How can I use this extension method? 8 47
c# regex: extract & replace text between braces 6 45
Name space syntax error 12 44
ASP.net Javascript use multiple sliders 2 19
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

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