繁体   English   中英

将dropdownlist选择的值转换为双变量asp.net Web表单

[英]get dropdownlist selected value into double variable asp.net web forms

我需要将下拉列表值传递给double变量。

    <asp:DropDownList ID="Drpdownlist" runat="server" Font-Names="Arial" Font-Size="12pt" Height="20px" Width="100px">
        <asp:ListItem Selected="True" Value="0.5">0.5 %</asp:ListItem>
        <asp:ListItem Value="1">1 %</asp:ListItem>
        <asp:ListItem Value="1.5">1.5 %</asp:ListItem>
        <asp:ListItem Value="2">2 %</asp:ListItem>
        <asp:ListItem Value="2.5">2.5 %</asp:ListItem>
        <asp:ListItem Value="3">3 %</asp:ListItem>
        <asp:ListItem Value="3.5">3.5 %</asp:ListItem>
        <asp:ListItem Value="4">4 %</asp:ListItem>
        <asp:ListItem Value="4.5">4.5 %</asp:ListItem>
        <asp:ListItem Value="5">5 %</asp:ListItem>
    </asp:DropDownList>

有变数

double rate = .5;

你应该试试这个

double rate= Convert.ToDouble(DropDownList.SelectedValue.ToString());

你可以试试这个

double rate;
double.TryParse(Drpdownlist.SelectedValue, out rate); // rate will be assigned if the conversion is successful

从下面的链接中查看有关double.TryParse更多详细信息:

https://msdn.microsoft.com/zh-cn/library/994c0zb1%28v=vs.110%29.aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM