c# - How can I multiply values from 2 dropdown lists in asp.net and display the results in a text box? -
i have lot of dropdown lists building insurance app. each list has number of options given multiplier value. question how can multiply these values separate dropdown lists give myself final multiplier value in textbox? want use whatever value picked each dropdown list.
the lists formatted follows
<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>
i have been coding 2 weeks can point me in right direction. have not found similar in search here. guys!
it's important remember values going stored within dropdownlists strings, first step converting them numerical values, can done in many ways, example purposes, can use convert.todecimal()
method :
// convert points decimal var pointsvalue = convert.todecimal(points.selectedvalue); // convert selection other dropdownlist var policyvalue = convert.todecimal(otherpolicy.selectedvalue); // have both of these, can multiply them retrieve result var result = pointsvalue * policyvalue; // store result in textbox yourresulttextbox.text = result.tostring();
if have more dropdownlists or other elements need part of calculation, need ensure parse each of values , include them in calculation.