-1

I'm a junior in high school in a software engineer and web development class. My issue is i assigned a value to many of my asp control objects; however, i cannot figure out how to add and display their values. Here is my code:

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="pc.aspx.cs" Inherits="pc" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>

<title>Millennium Computers Online Order Form</title>
<link href="computer.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form name="c_order" id="c_order" runat="server" 
action="pc.aspx" method="post">


<table id="tb1" cellpadding="5" cellspacing="5" border="0" >
  <tr>

<!-- Logo and header information -->
    <td id="header" style="height: 65px">
    <img src="mclogog.jpg" alt="heading" />
    </td>
  </tr>
 <asp:Panel runat="server" ID="frmMillenium" >
<!-- Shipping info -->
<tr>
    <td id="specifications">
      <fieldset class="spec">
      <legend id="bill">Specifications</legend>
      <table width="100%" id="specs">   <!-- 100% -->
        <tr>
       <td><label for="fname" >Frame Color<span>*</span></label></td>
       <td><input type="text" name="fname" id="fname" size="27" />
       </td>
     </tr>
     <tr>
       <td><label for="address1">Keyboard Color<span>*</span></label></td>
       <td><input type="text" name="address1" id="address1" size="57" /></td>
     </tr>
     <tr>
       <td><label for="city">Touchpad Color<span>*</span></label></td>
       <td><input type="text" name="city" id="city" size="40" />
     </tr>
    <tr>
      <td colspan="2" id="ast">
        * = Required field, must be filled in.     <%--  <input id="news" type="checkbox" align="left" />  <label id="news">Check here if you'd like to receive our newsletter</label>  --%>
      </td>
      </td>

    </tr>
      </table>
      </fieldset>
      <p id="infotext">About Us</p>
      <p id="info">Welcome to Millenium Computers. Our website is designed to allow users to create their own computer. Our job is to make a computer most suited
      for you, and accomadate prices as well. We offer many differant computer features with our standard designed model. We have been building computers for over 
      20 years and we garuntee customer satisfaction. So, what are you waiting for? Build your computer now!</p>
    </td>
  </tr> 

<!-- End Shipping info -->   

<!-- Computer Options -->  

  <tr>
    <td>
      <fieldset class="build">
      <legend>Your Computer</legend>
      <table width="100%">
        <tr>
          <td><label for="proc">Processor speed:</label></td>       
          <td><asp:DropDownList name="proc" ID="proc" runat="server">
            <asp:ListItem value="ghz">2.4 GHz: $158</asp:ListItem>
            <asp:ListItem value="3.2ghz">3.2 GHz: $184</asp:ListItem>
            <asp:ListItem value="4ghz">4.0 GHz: $200</asp:ListItem>
        </asp:DropDownList>
          <%--<select name="proc" id="proc">
            <option>2.4 GHz: $158</option>
            <option>3.2 GHz: $184</option>
            <option>4.0 GHz: $200</option>
          </select>--%></td>
          <td><label for="mem" id="memory">Memory:</label></td>
          <td><asp:DropDownList name="mem" ID="mem" runat="server">
            <asp:ListItem value="1gb">1 GB: $20</asp:ListItem>
            <asp:ListItem value="2gb">2 GB: $30</asp:ListItem>
            <asp:ListItem value="4gb">4 GB: $80</asp:ListItem>
            <asp:ListItem value="8gb">8 GB: $180</asp:ListItem>
        </asp:DropDownList><%--<select name="mem" id="mem">
            <option>1 GB: $20</option>
            <option>2 GB: $30</option>
            <option value="4">4 GB: $80</option>
            <option>8 GB: $180</option>
          </select>--%></td>
        </td>
          <td rowspan="3" id="buildxtrs">
            <span id="txtExtras">Extra's</span><span id="chk">(check what you want)</span><br />
            <%--<input id="dvd" name="dvd" type="checkbox" />--%>
            <asp:checkbox for="dvd" id="dvd" runat="server" />
            <label for="dvd" id="dvdop">DVD player: $80</label><br />
            <%--<input id="cdb" name="cdb" type="checkbox" />--%>
            <asp:checkbox for="cdb" id="cdb" runat="server" />
            <label for="cd-b" id="cd-bop">CD burner: $30</label><br />
            <%--<input id="dvb" name="dvb" type="checkbox" />--%>
            <asp:checkbox for="dvb" id="dvb" runat="server" />
            <label for="dv-b" id="dv-bop">DVD burner: $110</label><br />
            <%--<input id="lan" name="lan" type="checkbox" />--%>
            <asp:checkbox for="lan" id="lan" runat="server" />
            <label for="lan" id="lanop">LAN card: $45</label><br />
            <%--<input id="mdm" name="mdm" type="checkbox" />--%>
            <asp:checkbox for="mdm" id="mdm" runat="server" />
            <label for="mdm" id="mdmop">Modem: $90</label><br />
          </td>
        </tr>
        <tr>
          <td><label for="hd">Hard Drive Size:</label></td>
          <td><asp:DropDownList name="hd" ID="hd" runat="server">
                <asp:ListItem value="240gb">240 GB: $80</asp:ListItem>
                <asp:ListItem value="500gb">500 GB: $100</asp:ListItem>
                <asp:ListItem value="750gb">750 GB: $150</asp:ListItem>
                <asp:ListItem value="1tb">1 TB: $219</asp:ListItem>
             </asp:DropDownList>
        <%--<select name="hd" id="hd">
            <option>240 GB: $80</option>
            <option>500 GB: $100</option>
            <option>750 GB: $150 </option>
            <option>1 TB: $219</option>
          </select>--%></td>
          <td><label for="mtr" id="monitor">Monitor Size:</label></td>
          <td><asp:DropDownList name="mtr" ID="mtr" runat="server">
                <asp:ListItem value="15">15": $100</asp:ListItem>
                <asp:ListItem value="17">17": $500</asp:ListItem>
                <asp:ListItem value="19">19": $760</asp:ListItem>
                <asp:ListItem value="21">21": $830</asp:ListItem>
          </asp:DropDownList>
          <%--<select name="mtr" id="mtr">
            <option>15": $100</option>
            <option>17": $500</option>
            <option>19": $760</option>
            <option>21": $830</option>
          </select> --%></td>
        </tr>
        <tr>
          <td><label for="cdr">USB Ports:</label></td>
          <td><asp:DropDownList name="cdr" ID="cdr" runat="server">
                <asp:ListItem value="1port">1 Port: No Charge</asp:ListItem>
                <asp:ListItem value="2port">2 Ports: $30</asp:ListItem>
                <asp:ListItem value="3port">3 Ports: $120</asp:ListItem>
                <asp:ListItem value="4port">4 Ports: $218</asp:ListItem>
          </asp:DropDownList>
          <%--<select name="cdr" id="cdr">
            <option>1 Port: No Charge</option>
            <option>2 Ports: $30</option>
            <option>3 Ports: $120</option>
            <option>4 Ports: $218</option>
          </select>--%></td>
        </tr>
        </fieldset>
          </td>
        </tr>      
      </table>




<!-- Payment information -->  


  <tr>
    <td>
      <fieldset class="case">
      <legend>Computer Case (Optional)</legend>
          <img src="51.99g.png" alt="Fire Case" style="height:100px;" />
          <%-- start here for radio buttons--%>
          <asp:RadioButton id="Radio1" value="fire" GroupName="plan" name="plan" runat="server"/><label for="plan">$51.99</label>
          <%--<input type="radio" id="Radio1" value="1" name="plan" />--%>
          <img src="69.99g.png" alt="Black Case" style="height:100px;" />
          <asp:RadioButton id="Radio2" value="black" GroupName="plan" name="plan" runat="server"/><label for="plan">$69.99</label>
          <%--<input type="radio" id="Radio2" value="2" name="plan" />--%>

          <img src="149.99g.png" alt="Blue-Orange Case" style="height:100px;" />
          <label for="plan3"><input type="radio" id="Radio3" value="3" name="plan" />$149.99</label>
      </fieldset>
      <fieldset class="pay">
      <legend id="pay" >Payment Information</legend>
      <table width="100%">
        <tr>
          <td><label for="card">Credit Card:</label></td>
          <td><select id="card" name="card">
            <option>Visa</option>
            <option>Master Card</option>
            <option>American Express</option>
            <option>Discover</option>
          </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <label for="exp">Expires On:</label>
          <select id="exp" name="exp">
            <option>01</option><option>02</option><option>03</option><option>04</option>
            <option>05</option><option>06</option><option>07</option><option>08</option>
            <option>09</option><option>10</option><option>11</option><option>12</option>
          </select>&nbsp;/&nbsp;
          <select>
            <option>2006</option>
            <option>2007</option>
            <option>2008</option>
            <option>2009</option>
            <option>2010</option>
            <option>2011</option>
            <option>2012</option><option>2013</option>
          </select></td>
        <tr>
          <td><label for="cname">Name On Card:</label></td>
          <td><input id="cname" name="cname" type="text" size="53" /></td>
        </tr>
        <tr>
         <td><label for="cnum">Card Number:</label></td>
         <td><input id="cnum" name="cnum" type="password" size="54" /></td>
       </tr> 
       <tr>
         <td><label for="pnum">Phone Number:</label></td>
         <td><input id="pnum" name="pnum" type="text" size="53" /></td>
       </tr> 
    </tr>
      </table>
      </fieldset>
      <img  id="modelimg" src="milleniumcomputergo.png" alt="Millenium Computer" />
      <p id="model">One of our hand-constructed laptops</p>


    </td>
  </tr>    

<!-- Buttons -->  
  <tr>
    <td>
      <table>
    <tr>

      <td align="center">
     onclick="calculatePrice">Submit Order</button>--%>
      <asp:Button ID="btnSubmit" runat="server" Text="Submit Order" onclick="btnSubmit_Click"/>
      </td>

      <td align="left">
      <button id="cancel" name="cancel" type="reset" value="cancel">Cancel</button>
      </td>

    </tr>
      </table>

    </td>
  </tr>


</asp:Panel>    
</form>

</body>
</html>

and my cs page:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class pc : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        frmMillenium.Visible = false;

        int total;
    }

}

so again, my objective is to add all the selected values of the user (ex all the radio buttons and drop down list selections selected) and add them together and display the total. Any help would be greatly appreciated, Thanks!

2
  • 1
    This is ASP.NET, not 'classic ASP'. May 24, 2013 at 17:59
  • Add what values? Display where? All this is is a code dump and an almost-empty button click event. May 24, 2013 at 18:00

1 Answer 1

0

in the .cs or code behind page, you can reference the values for the controls on your page by simply referencing the control id name and the appropriate property. If your using any of the Visual Studio development platform, it should automatically (using intellisense) show you the methods and properties of the control you're referencing. Example from your code (Note..crude sample below and this is free hand so errors may abound...)

//Sum costs  (note: change your total data type to double)  
total = 0;
    double memCost;
    if(Double.TryParse(mem.SelectedItem.Text.SubString(mem.SelectedItem.Text.IndexOf("$")+1), out memCost) { total += memCost; }
    //add a value property to the dvd (and othercheckboxes) with the dollar amount and do the following
    if(dvd.checked){ total += dvd.value; }
    //rinse and repeat...

//Display results
string Summary = string.Empty;
if(mem.SelectedItem.Text != string.Empty){ Summary = Summary + mem.SelectedItem.Text + "<br />"; }
//rinse and repeat
//Add a littleral control to your form and assign the "Text" property the Summary variable above

Hope this helps get you started...

Dave

1
  • Thank you very much, your example really helped and made sense. I appreciate it! Justin. May 28, 2013 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.