-1

私はソフトウェア エンジニアと Web 開発クラスの高校 3 年生です。私の問題は、多くの asp コントロール オブジェクトに値を割り当てたことです。ただし、それらの値を追加して表示する方法がわかりません。これが私のコードです:

 <%@ 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>

そして私のcsページ:

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;
    }

}

繰り返しますが、私の目的は、ユーザーが選択したすべての値 (選択したすべてのラジオ ボタンとドロップダウン リストの選択など) を追加し、それらを合計して合計を表示することです。どんな助けでも大歓迎です、ありがとう!

4

1 に答える 1

0

.cs またはコード ビハインド ページでは、コントロール ID 名と適切なプロパティを参照するだけで、ページ上のコントロールの値を参照できます。Visual Studio 開発プラットフォームのいずれかを使用している場合は、参照しているコントロールのメソッドとプロパティが (intellisense を使用して) 自動的に表示されます。あなたのコードの例(注..以下の粗いサンプルであり、これはフリーハンドであるため、エラーがたくさんある可能性があります...)

//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

これがあなたが始めるのに役立つことを願っています...

デイブ

于 2013-05-24T18:21:03.213 に答える