在文本框中显示计算值

时间:2014-06-05 20:16:55

标签: asp.net

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

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

        }
        protected void Click_St_Click(object sender, EventArgs e)
        {
            double x1 = Convert.ToDouble(DropDownList2.SelectedItem.Text);
            double x2 = Convert.ToDouble(DropDownList3.SelectedItem.Text);
            double x3 = Convert.ToDouble(DropDownList5.SelectedItem.Text);
            double x4 = Convert.ToDouble(DropDownList7.SelectedItem.Text);
            double x5 = Convert.ToDouble(DropDownList9.SelectedItem.Text);
            double x6= Convert.ToDouble(DropDownList11.SelectedItem.Text);
            double a = Convert.ToDouble(DropDownList16.SelectedItem.Text);
            double b = Convert.ToDouble(DropDownList17.SelectedItem.Text);
            double c = Convert.ToDouble(DropDownList18.SelectedItem.Text);


        //  Number of inverters calculation
            double totalpower = Convert.ToDouble(x1+x2+x3+x4+x5+x6);
           double charge = Convert.ToDouble(totalpower/c);
            txtCharge_Controller.Text = Convert.ToSingle(charge);
          }
    }
}

我写这些代码来为我计算并在文本框上显示答案,但代码不正确,表明你不能将float转换为括号中代码行上的字符串(txtCharge_Controller.Text = Convert.ToSingle(收费);)。我无法转换它请有人帮助我

1 个答案:

答案 0 :(得分:0)

将行更改为:

txtCharge_Controller.Text = charge.ToString();