日期:2014-05-17  浏览次数:20488 次

Gridview 单元格文本 String 转 float



 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //如果是绑定数据行 
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
        //自动计算8.5单价X数量后的金额 
            if (e.Row.Cells[7].Text != null)
            {
                float Pbdiscount = Convert.ToSingle(e.Row.Cells[6].Text.Trim()); //8.5折后单价
                float Enum = Convert.ToSingle(e.Row.Cells[7].Text.Trim()); //数量
                String sumEprice =(Pbdiscount*Enum).ToString(); //金额
                e.Row.Cells[8].Text = sumEprice;
            }
         }
     }


我想编辑这行数量的数据时,当用户填入后,后面的金额会自动计算出来。
但是调试的时候提示这个错误。是不是我的思路错了,有什么办法解决?
gridview string

------解决方案--------------------

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //如果是绑定数据行 
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
        //自动计算8.5单价X数量后的金额 
            if (e.Row.Cells[7].Text != null)