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 =0;
if (e.Row.Cells[6].Text.Trim()!="")
{
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;
}
}
}
float aa;
bool flag = float.TryParse("", out aa);
if (flag)
Console.WriteLine("yes");
else
Console.WriteLine("no");