Solved

DropDownList and Radio button selections perform calculation to a text box

Posted on 2011-03-23
6
350 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 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.net Markup for Sub Menu 2 65
Query in AngularJS 8 84
Web page design problem 3 42
Need help for captcha 2 42
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

710 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