2016-06-01 9 views
0

私は保険アプリのために構築しているドロップダウンリストがたくさんあります。各リストには、乗数の値が与えられた場合のオプションがいくつかあります。私の質問は、テキストボックス内の最終乗数値を得るために、別々のドロップダウンリストからこれらの値をどのように乗算できますか?私は、各ドロップダウンリストから選択された値を使用したい。私は約2週間をコードしているasp.netの2つのドロップダウンリストの値をどのように乗算して結果をテキストボックスに表示できますか?

<asp:DropDownList id="points" runat="server"> 
    <asp:ListItem Value="1.00">0</asp:ListItem> 
    <asp:ListItem Value="1.05">1</asp:ListItem> 
    <asp:ListItem Value="1.10">2</asp:ListItem> 
    <asp:ListItem Value="1.18">3</asp:ListItem> 
    <asp:ListItem Value="1.25">4</asp:ListItem> 
    <asp:ListItem Value="1.32">5</asp:ListItem> 
    <asp:ListItem Value="1.40">6</asp:ListItem> 
    <asp:ListItem Value="1.47">7</asp:ListItem> 
    <asp:ListItem Value="1.55">8</asp:ListItem> 
    <asp:ListItem Value="1.62">9</asp:ListItem> 
    <asp:ListItem Value="1.70">10</asp:ListItem> 
    <asp:ListItem Value="1.77">11</asp:ListItem> 
</asp:DropDownList> 
<asp:DropDownList id="OtherPolicy" runat="server"> 
    <asp:ListItem value="1.20">Yes</asp:ListItem> 
    <asp:ListItem value="1.00">No</asp:ListItem> 
</asp:DropDownList> 

を次のように

リストがフォーマットされているので、うまくいけば、誰かが正しい方向に私を指すことができます。私はここでの検索で似たようなものは見つかりませんでした。みんなありがとう!

+0

私はこのプロジェクトでVisual Studio 2012を使用していますので、何でも使えます。 –

答えて

2

DropDownLists内に格納される値は文字列であるため、最初の手順で数値を数値に変換しますが、これはさまざまな方法で行うことができますが、あなたはより多くのDropDownListsまたはこの計算の一部である必要がある他の要素を持っている場合、あなたはちょうどあなたがそれらの値のそれぞれを解析し、あなたにそれらが含まれていることを確認する必要があるでしょう

// Convert your Points to a decimal 
var pointsValue = Convert.ToDecimal(points.SelectedValue); 

// Then convert your selection from your other DropDownList 
var policyValue = Convert.ToDecimal(OtherPolicy.SelectedValue); 

// Now that you have both of these, you can multiply them to retrieve your result 
var result = pointsValue * policyValue; 

// Store your result in another TextBox 
YourResultTextBox.Text = result.ToString(); 

Convert.ToDecimal()メソッドを使用することができます計算。

+0

お返事ありがとうございます、それは完全に意味があります。それらの値が変換されて乗算されたら、結果を印刷する最も簡単な方法は何ですか? –

+0

私が提供した例で示すように、結果を 'TextBox'に格納するだけで済みます。 –

関連する問題